【问题标题】:google geocode vai ajax with jsonp, giving an errorgoogle geocode vai ajax with jsonp,给出错误
【发布时间】:2012-04-10 03:39:37
【问题描述】:

我正在尝试使用带有 jsonp 的谷歌地理编码 vai ajax,这是代码

    jQuery("#getaddress").on("click", function () {
        jQuery.ajax({
            dataType: 'jsonp',
            url: 'http://maps.googleapis.com/maps/api/geocode/json',
            data: {
                address: 'rajshahi',
                sensor: false
            },
            success:function(results){
            console.log(results);
        }
    });

});

josn return 很好,但它给出了这个错误

invalid label
    [Break On This Error]   

    "results" : [

    json?c...6919370 (line 2, col 3)

请告诉我需要做些什么来解决这个问题。

【问题讨论】:

    标签: ajax google-maps-api-3 geocode


    【解决方案1】:

    我不熟悉 Google Geocoder API,但它看起来不支持 JSONP 请求,即返回纯 JSON 并且不将其包装在 javascript 函数中。您需要按照documentation

    中的说明使用 google.maps.geocoder

    【讨论】:

      【解决方案2】:

      这可能对你有帮助....

      var district = $('#district').val();
              var vdc = $('#vdc').val();
              var location = $('#locate').val();
      
      
              var myAddressQuery = location +","+ vdc+","+district ;
              var geocoder = new google.maps.Geocoder(); 
              geocoder.geocode(
                  { address : myAddressQuery, 
                    region: 'no' 
                  }, function(results, status){
                        if(status==google.maps.GeocoderStatus.OK){
                          var lat= results[0].geometry.location['Ya'];
                          var lng = results[0].geometry.location['Za']
                          position = new OpenLayers.LonLat(lng,lat).transform( fromProjection, toProjection);
                          data.openlayers.setCenter(position,zoom);  
                       }
      
              }); 
      

      更多您可以访问 https://developers.google.com/maps/documentation/javascript/geocoding?hl=no-NO

      【讨论】:

        猜你喜欢
        • 2017-12-18
        • 1970-01-01
        • 2018-09-11
        • 1970-01-01
        • 2017-01-24
        • 1970-01-01
        • 1970-01-01
        • 2018-08-17
        • 1970-01-01
        相关资源
        最近更新 更多