如何修复Uncaught InvalidValueError:setPosition:不是LatLng或LatLngLiteral:属性lat:不是数字? [英] How to fix Uncaught InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number?

查看:695
本文介绍了如何修复Uncaught InvalidValueError:setPosition:不是LatLng或LatLngLiteral:属性lat:不是数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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


错误:未捕获InvalidValueError:setPosition:不是LatLng或LatLngLiteral:in属性lat:不是数字%7Bmain,adsense,geometry ,zombie%7D.js:25


这里是我的地图初始化:

  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:{
位置:google.maps.ControlPosition.TOP_LEFT,
},
zoomControl:true,
zoomControlOptions :{
style:google.maps.ZoomControlStyle.LARGE,
positi on:google.maps.ControlPosition.LEFT_CENTER,
},
scaleConrol:true,
scaleControlOptions:{
position:google.maps.ControlPosition.TOP_LEFT,
} ,
});
map.setCenter(new google.maps.LatLng(49.477643,9.316406));

这里是我的错误部分:

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

//获取信息
$ .getJSON(traders_uri,function(data){
//查看信息
$ .each (data.traders,function(i,trader){
var icon = options.icon_image_uri;
$ b $ var markerIcon = new google.maps.MarkerImage(icon,
// This标记宽20像素,高32像素
新google.maps.Size(25,25),
//此图片的原点为0,0
new google.maps .Point(0,0),
//这个图片的锚是0.32的旗杆底部。
new google.maps.Point(0,32)
) ;

var html ='test';

/ *来自铬调试器的信息
trader:Object
geo:Object
lat: 49.014821
lon:10.985072

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

这里是新google.maps.Marker()中的错误* /
var marker = new google.maps.Marker({
position:myLatlng,
ma p:map,
图标:markerIcon,
});

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

编辑:drawtraders的调用

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

我使用这个例子 Info Window



我希望有人能帮助我。



编辑:



小提琴无法使用



小提琴的工作原理


<

Uncaught InvalidValueError:setPosition:不是一个LatLng或LatLngLiteral:在属性lat:不是一个数字

表示您没有将数字传递给google.maps.LatLng构造函数。根据你的评论:

  / *来自铬调试器的信息
交易者:对象
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)); 


i'm trying to port my googlemaps v2 functions to v3.

But somehow i stuck in a strange error and i could not find, what i'm doing wrong.

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

Here my map initialisation:

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));

and here the part with my error:

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
});
}

Edit: the call of drawTraders

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

I was using this example Info Window

I hope someone could help me.

Edit:

Fiddle which is not working

Fiddle which works

解决方案

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

Means you are not passing numbers into the google.maps.LatLng constructor. Per your comment:

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

*/

trader.geo.lat and trader.geo.lon are strings, not numbers. Use parseFloat to convert them to numbers:

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

这篇关于如何修复Uncaught InvalidValueError:setPosition:不是LatLng或LatLngLiteral:属性lat:不是数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆