简体   繁体   English

如何在javascript中进行地理编码以获取经纬度?

[英]How can i do geocoding in javascript to get lat and long?

This is how i am trying, but i am not getting any response. 这是我正在尝试的方式,但是我没有得到任何回应。 What could be wrong ? 有什么问题吗?

API used: 使用的API:

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=***&sensor=false"
            type="text/javascript"></script>



function initialize() {
     var addrLookup = 'San Diego , CA   92101';
     var geoCoder = new google.maps.Geocoder();
     var geoRequest = { address: addrLookup };
     geoCoder.geocode(geoRequest,function(results,status){
        window.alert("response");
        console.log(status);
     });
}

Slightly modify your script: 稍微修改脚本:

<html>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
        function initialize() {
              var addrLookup = 'San Diego , CA   92101';
              var geoCoder = new google.maps.Geocoder();
              var geoRequest = { address: addrLookup };
              geoCoder.geocode(geoRequest,function(results,status){

                  console.log('latitude: ',results[0].geometry.location.lat());
                  console.log('longitude: ',results[0].geometry.location.lng());
              });
           }
    </script>

    <body onload="initialize()">


</body></html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Javascript将Lat和Long转换为英国邮政编码 - how do i convert Lat and Long to uk postcode with Javascript 我如何通过给定的纬度/经度获取地址 - How do i get address by given lat/long 如何在自定义平铺的Google地图中获取经度/纬度? - How do I get lat/long in a custom tiled google map? Bing地图。 如何通过lat和long获取地址? - Bing maps. How can I get address by lat and long? 如何在javascript中使用经纬度长的对象制作Nokie HERE地图折线 - How can I make Nokie HERE map polyline using object of lat long in javascript 如何使用JavaScript验证经纬度和一次文本输入 - How can I validate lat and long within one text input with javascript 如何使用arcGis JavaScript获取地址的纬度 - how to get Lat Long of an Address using arcGis JavaScript 如何在Google Maps JS API中获取仍包含一组Lat / Long坐标的最小LatLngBounds? - How can I get the smallest LatLngBounds that still contains a set of Lat/Long Coordinates in Google Maps JS API? 如何在 node.js 中使用地理定位来获取用户设备的纬度/经度 - How can I use geolocation in my node.js to get user device lat/long 如何从字符串中提取lat和long值? - How can i extract lat and long values from string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM