2011-04-11 31 views
7

sonraki örnek http://jsbin.com/inepo3/7/edit tarafından LNG ve Google Maps API lat koordinatlarını almaya çalışıyorum. 'Başarılı' bir açılır pencere bekliyorum, ancak 'Hata' açılır penceresini göstermeye devam ediyor. Google harita isteği, doğru json geri bildirimini verir (firebug tarafından kontrol edilir).() isteği

<script type="text/javascript"> 
    $().ready(function() { 

     $.fn.getCoordinates=function(address){ 

      $.ajax(
      { 
       type : "GET", 
       url: "http://maps.google.com/maps/api/geocode/json", 
       dataType: "jsonp", 
       data: { 
        address: address, 
        sensor: "true" 
       }, 
       success: function(data) { 
        set = data; 
        alert(set); 
       }, 
       error : function() { 
        alert("Error."); 
       } 
      }); 
     }; 

     $().getCoordinates("Amsterdam, Netherlands"); 
    }); 
</script> 

Bu sorunun nasıl giderileceğini bilen var mı?

<script type="text/javascript"> 
    $().ready(function() { 
     var user1Location = "Amsterdam, Netherlands"; 
     var geocoder = new google.maps.Geocoder(); 
     //convert location into longitude and latitude 
     geocoder.geocode({ 
      address: user1Location 
     }, function(locResult) { 
      console.log(locResult); 
      var lat1 = locResult[0].geometry.location.lat(); 
      var lng1 = locResult[0].geometry.location.lng(); 
      $("#testDiv").html("latitude:" + lat1 + "<p>longitude:" + lng1 + "</p>"); 
     }); 
    }); 
</script> 
+0

google harita API sürümü: Biz temelde Tweet'in adresi (. IE Londra, Madrid veya vb Gürcistan) almak ve Google Haritalar'ın Geocoder Servisi kullanarak LatLng içine gerçek adresiyle dönüştürmek için twitter kullanılır? – kjy112

+0

Ben shure değilim, sanırım v2 (kullanılmış haritalar url'yi belki bir sürüme dönüştürür müsünüz?) –

+0

Artık eminim ki V3 şimdi tekrar bakıyor. – kjy112

cevap

9

Google Harita API V3 dış kütüphaneleri de zorlaştırır:

Selamlar, Guido Lemmens

DÜZENLEME

Ben jQuery kombine Google Maps JavaScript API kullanarak bir bether çözüm buldu JSONP ile çalışmak. İşte bu konuda bir blog yazısı var.

JSONP and Google Maps API Geocoder Plus A Fix w/ jQuery


Geocoding almanın diğer bir yolu Google Map V3 API Geocoder Service kullanmaktır. JSONP yerine Google Map V3 Geocoder Hizmetini kullanmak üzere değiştirdiğinizde benzer bir sorunu olan bir kişiye yardımcı olduğum bir örnek. Bu temelde çekirdeğidir bu JSFiddle Demo:

bir göz atın.

$.getJSON(
    url1, function(results) { // get the tweets 
     var res1 = results.results[0].text; 
     var user1name = results.results[0].from_user; 
     var user1Location = results.results[0].location; 

     // get the first tweet in the response and place it inside the div 
     $("#last-tweet1").html(res1 + "<p>from: " + user1name + " (" + user1Location + ")</p><p>"); 
     //convert location into longitude and latitude 
     geocoder.geocode({ 
      address: user1Location 
     }, function(locResult) { 
      console.log(locResult); 
      var lat1 = locResult[0].geometry.location.lat(); 
      var lng1 = locResult[0].geometry.location.lng(); 
      $("#testDiv").html("latitude:" + lat1 + "<p>longitude:" + lng1 + "</p>"); 
     }); 
    }); 
+1

Cool, örneğinizi çalıştım ve orijinal gönderime ekledim. Bu mükemmel çalışıyor! –

+0

çok yararlı, teşekkürler! – montrealist

+0

Çapraz alan adı hatası olsun, neden? –