Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 谷歌地图API检测用户位置_Google Maps_Jquery Mobile - Fatal编程技术网

Google maps 谷歌地图API检测用户位置

Google maps 谷歌地图API检测用户位置,google-maps,jquery-mobile,Google Maps,Jquery Mobile,我正在学习jquery mobile。我遇到了一个使用以下GoogleMapsAPI的示例代码 http://maps.google.com/maps/api/js?sensor=false 代码用于检测用户的当前位置 function getPosition(position) { var lat = position.coords.latitude; var lng = position.coords.longitude; var latl

我正在学习jquery mobile。我遇到了一个使用以下GoogleMapsAPI的示例代码

http://maps.google.com/maps/api/js?sensor=false
代码用于检测用户的当前位置

function getPosition(position) {
        var lat = position.coords.latitude;
        var lng = position.coords.longitude;

        var latlng = new google.maps.LatLng(lat, lng);
        var geocoder = new google.maps.Geocoder();

        if (geocoder) {
          geocoder.geocode({'latLng': latlng}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
              if (results[1]) {
            //window.alert(results[1].address_components[0].long_name);
            var locationVal = results[1].address_components[0].long_name;
            var stateVal = results[1].address_components[1].short_name;

            var location = document.getElementById('location');

            location.value = locationVal;

              }
            }
          });
        }
          }
          if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(getPosition); 
          }
在上面的代码中,结果数组中有一个address\u components数组。如何确定results对象的属性,然后再确定address_组件的属性?

请参见此处:

顺便说一句,如果您使用的是API,则必须将sensor设置为true