gpt4 book ai didi

javascript - 无法在 Google Maps Api v3 中添加标记

转载 作者:行者123 更新时间:2023-11-30 10:29:37 24 4
gpt4 key购买 nike

从昨天开始,我就在尝试在 Google Maps Api v3 中添加标记。我阅读了文档和所有内容。这是我的代码:

<script type="text/javascript">
var map;
function initialize() {

var mapOptions = {

center: new google.maps.LatLng(28.63, 77.21),
zoom: 8,
disableDefaultUI: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);


}
// google.maps.event.addDomListener(window, 'load', initialize);

function getFillingDetails(){
var vehicleId = $('#selectVehicle option:selected').val();
$.getJSON('getFillingDetails.php', {id : vehicleId}, function(data){
var lat = [];
var lon = [];
var price = [];
$.each(data, function(key, value){
lat.push(value.latitude);
lon.push(value.longitude);
price.push(value.price);
});
});

var myLatlng = new google.maps.LatLng(23.72,77.10);

var marker = new google.maps.Marker({
position: new google.maps.LatLng(23.72, 72.100),
map: map,
});

}
</script>

我觉得一切都很好。 initialize()函数在body标签的onload之后被调用。当我点击一个按钮时,getFillingDetails() 函数被调用。但我仍然没有成功。

最佳答案

您在以下位置有语法错误:

var marker = new google.maps.Marker({
position: new google.maps.LatLng(23.72, 72.100),
map: map, <--- get rid of this comma
});

下次您应该在开发人员控制台中查看是否有任何错误。

关于javascript - 无法在 Google Maps Api v3 中添加标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17667790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com