2015-07-20 48 views
-1

你好傢伙我有一個問題,當我使用google.maps.LatLng的方法時,每次使用它時都會自動將經度值改爲不同的值,也是如此長時間在谷歌地圖中使用,所以我不能在我的地圖中添加標記與位置。是否有人知道以不同的方式來做到這一點或問題是什麼。我從json sting中獲取數據並將其加載到數組中檢查代碼下面。谷歌地圖(google.maps.LatLng)更改值lat lng

我的緯度和經度

lat,lng

使用後google.maps.LatLng經緯度 google.maps.LatLng

var map; 
var markers = []; 
var child_details = []; 

function initialize() { 
    var haightAshbury = new google.maps.LatLng(34.8055973, 32.4104341); 
    var mapOptions = { 
     zoom: 12, 
     center: haightAshbury, 
     mapTypeId: google.maps.MapTypeId.TERRAIN 
    }; 
    map = new google.maps.Map(document.getElementById('map-canvas'), 
     mapOptions); 

    // This event listener will call addMarker() when the map is clicked. 
    google.maps.event.addListener(map, 'click', function(event) { 
     addMarker(event.latLng); 
    }); 
} 


function load_children(child_list) { 

    var marker; 
    var obj = JSON.parse(child_list); 

    for (var i in obj) { 
     child_details.push([obj[i].cid, obj[i].uid, obj[i].Name, obj[i].Surname, 
      obj[i].lat, obj[i].lng, obj[i].timestamp, 
      obj[i].Sensor 
     ]); 
    } 

    setUpMarkers(map, child_details); 
} 


function setUpMarkers(map, locations) { 

    alert('set up'); 
    for (var i = 0; i < locations.length; i++) { 
     var loc = locations[i]; 
     alert("lat" + loc[4] + "lng " + loc[5]); 
     //The problem is here 
     var myLatLng = new google.maps.LatLng(loc[4], loc[5]); 
     //After i use this method to get Lat Lng i get wrong lng 
     alert(myLatLng); 
     var marker = new google.maps.Marker({ 
      position: myLatLng, 
      map: map, 
      title: loc[3] 

     }); 
     markers.push(marker); 
    } 

} 


// Add a marker to the map and push to the array. 
function addMarker(location) { 
    var marker = new google.maps.Marker({ 
     position: location, 
     map: map 
    }); 
    markers.push(marker); 

} 

// Sets the map on all markers in the array. 
function setAllMap(map) { 
    for (var i = 0; i < markers.length; i++) { 
     alert('adding marker' + markers[i]); 
     markers[i].setMap(map); 
    } 
} 

// Removes the markers from the map, but keeps them in the array. 
function clearMarkers() { 
    setAllMap(null); 
} 

// Shows any markers currently in the array. 
function showMarkers() { 
    setAllMap(map); 
} 

// Deletes all markers in the array by removing references to them. 
function deleteMarkers() { 
    clearMarkers(); 
    markers = []; 
} 
+0

嘗試在包裝'parseFloat'值,當你構建你的latLng,即'無功myLatLng =新google.maps.LatLng(parseFloat(LOC [4 ]),parseFloat(loc [5]));' – duncan

+0

你的意思是座標被截斷,所以標記不能精確定位精確點? –

+2

你的意思是「在Google地圖中使用太久了」是什麼意思?沒關係,它很長,谷歌地圖會忽略其他小數位。我認爲你的錯誤是在別的地方。什麼不適用於你的應用程序?它會拋出一些錯誤嗎? –

回答

相關問題