我尝试使用以下脚本在Google地图上添加多个标记,但没有更改,
我需要使用的坐标发布在我访问的输入字段上:var latidudedb = document.getElementById("latitude").value;
var longitudedb = document.getElementById("longitude").value;
请帮助我,你的帮助很高,
Javascript代码已修改:
var lat = -1.970579 //default latitude
var lng = 30.104429; //default longitude
var homeLatlng = new google.maps.LatLng(lat, lng); //set default
coordinates
var homeMarker = new google.maps.Marker({ //set marker
position: homeLatlng, //set marker position equal to the default coordinates
map: map, //set map to be used by the marker
draggable: true //make the marker draggable
});
var myOptions = {
center: new google.maps.LatLng(-1.935114, 30.082111), //set map center
zoom: 17, //set zoom level to 17
mapTypeId: google.maps.MapTypeId.ROADMAP //set map type to road map
};
var map = new
google.maps.Map(document.getElementById("map_canvas"),myOptions);
//initialize the map
//if the position of the marker changes set latitude and longitude to
//current position of the marker
google.maps.event.addListener(homeMarker, 'position_changed', function(){
var lat = homeMarker.getPosition().lat(); //set lat current latitude where the marker is plotted
var lng = homeMarker.getPosition().lng(); //set lat current longitude where the marker is plotted
});
$('#plot_marker').blur(function () {
$.post('/dashboard/names/DateString', $('mapform').serialize(), function
(data) {
},
);
homeMarker.setMap(map); //set the map to be used by marker
homeMarker.setPosition(map.getCenter()); //set position of marker equal to
the current center of the map
map.setZoom(17);
//get latitude and longitude from interface
var latidudedb = document.getElementById("latitude").value;
var longitudedb = document.getElementById("longitude").value;
//set the coordinates of the selected place
var position = new google.maps.LatLng(latidudedb, longitudedb);
//set marker position
homeMarker.setMap(map);
homeMarker.setPosition(position);
//set the center of the map
map.setCenter(homeMarker.getPosition());
map.setZoom(17);