google maps从邮政编码获取纬度和经度

如何解决google maps从邮政编码获取纬度和经度

| 是否可以仅通过邮政编码来使用Google Api获得经度和纬度? 谢谢您的提示,再见     

解决方法

只需创建一个ѭ0的实例并调用其ѭ1,方法,即可传入一个对象,该对象具有使其成为
GeocoderRequest
所必需的属性。 从而:
var geocoder = new google.maps.Geocoder();
geocoder.geocode({address: /* zip you got from user input */},function(results_array,status) { 
        // Check status and do whatever you want with what you get back
        // in the results_array variable if it is OK.
        // var lat = results_array[0].geometry.location.lat()
        // var lng = results_array[0].geometry.location.lng()
});
    ,您可以交替使用: 网址:http://maps.googleapis.com/maps/api/geocode/json?address=santa+cruz&components=postal_code:695564&sensor=false 只需在jquery-ajax中调用此url,您将得到较长的结果。 使用jquery-ajax的示例:
$(document).ready(function(){

    var zipcode = 695564;

    $.ajax({
       url : \"http://maps.googleapis.com/maps/api/geocode/json?address=santa+cruz&components=postal_code:\"+zipcode+\"&sensor=false\",method: \"POST\",success:function(data){
           latitude = data.results[0].geometry.location.lat;
           longitude= data.results[0].geometry.location.lng;
           alert(\"Lat = \"+latitude+\"- Long = \"+longitude);
       }

    });
});
来自Google api的示例JSON结果:
{
   \"results\" : [
      {
         \"address_components\" : [
            {
               \"long_name\" : \"695564\",\"short_name\" : \"695564\",\"types\" : [ \"postal_code\" ]
            },{
               \"long_name\" : \"Thiruvananthapuram\",\"short_name\" : \"TVM\",\"types\" : [ \"administrative_area_level_2\",\"political\" ]
            },{
               \"long_name\" : \"Kerala\",\"short_name\" : \"KL\",\"types\" : [ \"administrative_area_level_1\",{
               \"long_name\" : \"India\",\"short_name\" : \"IN\",\"types\" : [ \"country\",\"political\" ]
            }
         ],\"formatted_address\" : \"Kerala 695564,India\",\"geometry\" : {
            \"bounds\" : {
               \"northeast\" : {
                  \"lat\" : 8.5894172,\"lng\" : 77.0210912
               },\"southwest\" : {
                  \"lat\" : 8.5616185,\"lng\" : 76.96664299999999
               }
            },\"location\" : {
               \"lat\" : 8.5753702,\"lng\" : 76.99310740000001
            },\"location_type\" : \"APPROXIMATE\",\"viewport\" : {
               \"northeast\" : {
                  \"lat\" : 8.5894172,\"lng\" : 76.96664299999999
               }
            }
         },\"partial_match\" : true,\"types\" : [ \"postal_code\" ]
      }
   ],\"status\" : \"OK\"
}
干杯..     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?