2011-11-14 7 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が短すぎます –

関連する問題