2011-08-09 47 views

回答

1

你可以這樣做:

var coords = ['(52.37253609047836, 4.868355474853502)', '(52.37253609047836, 4.868355474853502)', '(52.37253609047836, 4.868355474853502)']; 

var coordConverted = []; 

for (var i = 0; i < coords.length; i++) { 
    var values = coords[i].match(/\d+\.\d+/g); 
    coordConverted.push({ 
     latitude: values[0], 
     longitude: values[1] 
    }); 
} 

$.ajax({ 
    type: 'POST', 
    data: {coords: coordConverted}, 
    url: 'server' 
}) 

當且僅當,在服務器要求後變量數組coords。輸出看起來像這樣:

{coords: [{"latitude":"52.37253609047836","longitude":"4.868355474853502"},{"latitude":"52.37253609047836","longitude":"4.868355474853502"},{"latitude":"52.37253609047836","longitude":"4.868355474853502"}]} 
+0

嗨,與Array.toString看起來是這樣的:(52.37253609047836,4.868355474853502),(52.36247380473571,4.86663886108397),(52.36163517746424,4.88037177124022),(52.36142551815929,4.903374395751939)...例如。可以有很多值 - 不只是兩個。有沒有機會發布這個? – fillibuster

+0

數組中的每個項都是一個字符串? – Joe

+0

這些項目是數字:http://code.google.com/intl/zh-CN/apis/maps/documentation/javascript/reference.html#LatLng – fillibuster

1

喬伊幾乎在那裏。

lonLatArray = [....prepopulated...]; 
coords = []; 

for(var i=0;i<latLonArray.length;i++){ 
    coords.push({ 
     lat: lonLatArray[i].lat(), 
     lon: lonLatArray[i].lon() 
    }); 
} 

$.post("ajax.php",{data: coords},function(data){ 
    console.log("success"); 
}); 
相關問題