Javascript Google 地图错误不是 latlng 或 latlngliteral invalidvalueerror
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46935093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google maps error not a latlng or latlngliteral invalidvalueerror
提问by twan
I am looping some markers and add a lat and long to them but I keep getting this error:
我正在循环一些标记并向它们添加纬度和经度,但我不断收到此错误:
message
:
"not a LatLng or LatLngLiteral: not an Object"
name
:
"InvalidValueError"
And:
和:
InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number
This is my loop:
这是我的循环:
var bedrijvenlijst = []; // new array
$.each( bedrijven, function( key, value ) {
// console.log( key + ": " + value.plaats );
console.log(value.lng);
bedrijvenlijst.push({
title : value.title,
image : 'bbvdw.jpg',
address : value.straat + ' ' + value.plaats,
position : {
lat : value.lat,
lng : value.lng
},
markerIcon : 'marker-green.png'
}); // new item added in array
});
When I console log the lng or lat is just shows as a normal number like:
当我控制台日志时,lng 或 lat 仅显示为正常数字,例如:
4.23626
4.23626
Why do I get this error? If I just type the coordinates myself in the loop it works fine, so what is different when using value.latand value.lng? In the console it looks exactly the same as if I would type it myself.
为什么我会收到这个错误?如果我只是在循环中自己输入坐标它工作正常,那么使用value.latand时有什么不同value.lng?在控制台中,它看起来与我自己输入的完全一样。
回答by dev8080
The error message points to the property 'lat'; you're passing something that is not a number, it might be the string "4.36xxxx", so check for that.
错误消息指向属性“lat”;你传递的不是数字,它可能是字符串“4.36xxxx”,所以检查一下。
You could try:
你可以试试:
position : {
lat : parseFloat( value.lat ),
lng : parseFloat( value.lng )
},
回答by yohohohohohohoho
I think you need a Google Maps LatLng. You cant just take normal numbers for the positions of a marker.
我认为你需要一个谷歌地图 LatLng。您不能只为标记的位置取正常数字。
Like position = new google.maps.LatLng(lat,lng);
喜欢 position = new google.maps.LatLng(lat,lng);

