gpt4 book ai didi

javascript - 如何修复未捕获的 InvalidValueError : setPosition: not a LatLng or LatLngLiteral: in property lat: not a number?

转载 作者:IT王子 更新时间:2023-10-29 03:08:57 26 4
gpt4 key购买 nike

我正在尝试将我的 googlemaps v2 功能移植到 v3。

但不知何故我陷入了一个奇怪的错误,我找不到我做错了什么。

Error : Uncaught InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number %7Bmain,adsense,geometry,zombie%7D.js:25

这里是我的 map 初始化:

var map = new google.maps.Map(document.getElementById("map"),{
zoom:4
size:new google.maps.Size(580,440),
mapTypeControl: true,
mapTypeControlOptions: {
style:google.maps.MapTypeControlStyle.VERTICAL_BAR,
position: google.maps.ControlPosition.BOTTOM_CENTER,
},
panControl: true,
panControlOptions: {
position: google.maps.ControlPosition.TOP_LEFT,
},
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.LEFT_CENTER,
},
scaleConrol: true,
scaleControlOptions:{
position: google.maps.ControlPosition.TOP_LEFT ,
},
});
map.setCenter(new google.maps.LatLng(49.477643, 9.316406));

这里是我出错的部分:

function drawTraders(map, options) {
var traders_uri = options.traders_uri || '';
if ('' == traders_uri) {
return false;
}

// get the informations
$.getJSON(traders_uri, function(data) {
// look through the information
$.each(data.traders, function(i, trader) {
var icon = options.icon_image_uri;

var markerIcon = new google.maps.MarkerImage(icon,
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(25, 25),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(0, 32)
);

var html = 'test';

/*Information from chromium debugger
trader: Object
geo: Object
lat: "49.014821"
lon: "10.985072"

*/
var myLatlng = new google.maps.LatLng(trader.geo.lat,trader.geo.lon);

/*here is the error in new google.maps.Marker()*/
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon : markerIcon,
});

var infowindow = new google.maps.InfoWindow({
content: html
});
}

编辑:drawTraders 的调用

 drawTraders(map, {
traders_uri: "getTraders.php",
icon_image_uri: "icon-cms.gif",
});

我正在使用这个例子 Info Window

编辑:

Fiddle which is not working

Fiddle which works

最佳答案

Uncaught InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number

意味着您没有将数字 传递给 google.maps.LatLng 构造函数。根据您的评论:

/*Information from chromium debugger
trader: Object
geo: Object
lat: "49.014821"
lon: "10.985072"

*/

trader.geo.lat 和 trader.geo.lon 是字符串,不是数字。使用 parseFloat 将它们转换为数字:

var myLatlng = new google.maps.LatLng(parseFloat(trader.geo.lat),parseFloat(trader.geo.lon));

关于javascript - 如何修复未捕获的 InvalidValueError : setPosition: not a LatLng or LatLngLiteral: in property lat: not a number?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20585055/

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