2011-11-14 24 views
1

分割results[0].geometry.location時出錯。我試圖分裂這個TypeError:對象沒有方法'split'分割結果時出錯[0] .geometry.location

geocoder = new google.maps.Geocoder(); 
codeAddress(); 

function codeAddress() { 
    var address = "Karachi, Pakistan"; 
    geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      var variable = results[0].geometry.location; 
      // this will return latitutde and longitutde, I want to split this 
      // because it is in a format like (54.8773,99.8038994749) 
      var next = variable.split(","); 
      // this giving an error "TypeError: Object has no method 'split'" 
     } 
    }); 
} 

回答

5

location propertyLatLng實例,而不是一個數組。使用lat()lng()方法來提取座標:

var variable = results[0].geometry.location; 
var next  = [ variable.lat(), variable.lng() ]; 
+0

thanx ... @ mu太短 –

相關問題