gpt4 book ai didi

javascript - Google Maps API v3 有一个非常奇怪的错误?

转载 作者:行者123 更新时间:2023-11-30 09:03:31 25 4
gpt4 key购买 nike

在 google maps api v3 中,以下行有效:

var myLatlng = new google.maps.LatLng(50.082243,24.302628);

但是,以下不是:

var gpsPos = '50.082243,24.302628';
var myLatlng = new google.maps.LatLng(gpsPos);

这有多奇怪,或者更好的是,如何解决这个问题?


完整代码如下:

$("document").ready(function(){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps/api/js?sensor=false&region=SK&callback=initialize";
document.body.appendChild(script);
});

function initialize(){
var gpsPos = '50.082243,24.302628';
var myLatlng = new google.maps.LatLng(gpsPos);

var myOptions = {
zoom: 7,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
panControl: false,
zoomControl: true,
mapTypeControl: true,
scaleControl: false,
streetViewControl: false,
scrollwheel: false
}

var map = new google.maps.Map(document.getElementById("otvorena-aukcia-mapa"), myOptions);

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

最佳答案

根据docs您根本无法传递字符串。

您必须明确地将这两部分分开并将它们作为数字传递:

var gpsPos = '50.082243,24.302628';
var splitted = gpsPos.split(",");
var myLatlng = new google.maps.LatLng(splitted[0] - 0, splitted[1] - 0);
// '- 0' will automatically make it a number

关于javascript - Google Maps API v3 有一个非常奇怪的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7114723/

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