我正在嘗試將我的google mapma v2功能移植到v3。如何修復Uncaught InvalidValueError:setPosition:不是LatLng或LatLngLiteral:屬性lat:不是數字?
但不知何故,我陷入了一個奇怪的錯誤,我無法找到,我做錯了什麼。
Error : Uncaught InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number %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: {
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
我希望有人能幫助我。
編輯:
GSize是V2的事情。 MarkerImage是已棄用的v3構造,取而代之的是匿名的[Icon](https://developers.google.com/maps/documentation/javascript/reference#Icon)。 'trader.geo.lat,trader.geo.lon'的價值是什麼? – geocodezip
對不起,我還沒有看到它,但修復後google.maps.Size它仍然無法正常工作。這些值在註釋中。我不理解downvote,但確定 – demonking
您沒有發佈足夠的代碼來重現此問題。 – geocodezip