Update
Also, your global map
reference is never set to the actual map instance since you shadow it with a local var
same name.
var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
This should be just
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
You're using lat
and lng
for the marker position before they're initialized (unless they're globally set somewhere):
var newLatLng = new google.maps.LatLng(lat, lng);
marker.setPosition(newLatLng);
If you want to update the position of the same marker and not create a new one, you should simply be doing this:
$("#updateMap").click(function(){
var lat = parseFloat(document.getElementById('markerLat').value);
var lng = parseFloat(document.getElementById('markerLng').value);
var newLatLng = new google.maps.LatLng(lat, lng);
marker.setPosition(newLatLng);
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…