您好我正在尝试在Google地图上实施标记,但它无法正常工作,我只是粘贴我的脚本 请告诉我我在哪里做错了。谢谢
<script>
var map;
function initialize() {
var Longitude = document.getElementById('Longitude').value;
var Lattitude = document.getElementById('Lattitude').value;
console.log(Longitude + '' + Lattitude);
var map_canvas = document.getElementById('map_canvas');
var isDraggable = $(document).width() < 1000 == false;
var map_options = {
center: new google.maps.LatLng(Lattitude, Longitude),
zoom: 15,
draggable: isDraggable,
scrollwheel: false,
// navigationControl: false,
//mapTypeControl: false,
//scaleControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(map_canvas, map_options)
var myLatlng = new google.maps.LatLng(Longitude, Lattitude);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!',
animation: google.maps.Animation.DROP,
});
marker.setMap(map)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
答案 0 :(得分:0)
我的代码正常工作(虽然我伪造了lat而不是使用文本框)。
我可以提供一些建议:
* Make sure the google maps script and jQuery scripts are loaded before your code
* Ensure your textboxes are populated before the domready event fires
* When loading the page, press F12 and refresh. Check the console that pops up for errors
答案 1 :(得分:0)
嗯,你换了经度/纬度。 LatLng()首先要求格子(在你的地图上,地球上某些完全不同的部分可能有一个标记)。 只需将代码的这一部分更改为:
...
var myLatlng = new google.maps.LatLng(Lattitude, Longitude);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!',
animation: google.maps.Animation.DROP
});
//marker.setMap(map)
...
您不需要marker.setMap(地图)。这已经完成了map:map,