简体   繁体   English

如何使用Google Maps API v3从iPhone获取用户的位置?

[英]How to get the user's location from iPhone using Google Maps API v3?

I want to make a google map on the iPhone and show the user's location when they first open the site. 我想在iPhone上制作一个Google地图,并在用户首次打开该网站时显示其位置。

But i can't find this method on Google Maps v3 api. 但是我在Google Maps v3 api上找不到此方法。 So i think maybe the iPhone has the function to do this. 因此,我认为也许iPhone具有执行此操作的功能。 Does it? 可以?

You may want to use the W3C Geolocation API , which Safari on the iPhone supports. 您可能要使用iPhone上的Safari支持的W3C Geolocation API

Plotting a point on Google Maps using the position from the Geolocation API, will look something like this: 使用Geolocation API中的位置在Google Maps上绘制点将看起来像这样:

if (navigator.geolocation) { 
  navigator.geolocation.getCurrentPosition(function(position) {  

    var point = new google.maps.LatLng(position.coords.latitude, 
                                       position.coords.longitude);

    // Initialize the Google Maps API v3
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 15,
      center: point,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    // Place a marker
    new google.maps.Marker({
      position: point,
      map: map
    });
  }); 
} 
else {
  alert('W3C Geolocation API is not available');
} 

Make sure that the Google Maps API v3 is included in your web document: 确保您的网络文档中包含Google Maps API v3:

<script src="http://maps.google.com/maps/api/js?sensor=true" 
        type="text/javascript"></script>

... and that you have a placeholder for the map canvas: ...并且您有一个占位符用于地图画布:

<div id="map" style="width: 500px; height: 400px;"></div>

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

相关问题 如何使用Google Maps API v3获取客户位置? - How to get Client location using Google Maps API v3? 如何从Google Maps JavaScript API V3获取用户形状并进行分析 - How to get user's shape from Google Maps JavaScript API V3 and analyze it iPhone Google Maps API V3用户当前位置并显示餐厅 - iPhone Google Maps API V3 User Current location and show Restaurants 谷歌地图api v3,定义用户当前位置 - Google maps api v3, defining user current location 尝试使用Google API v3从地址获取位置 - trying to get location from address using google api v3 如何从Google Maps V3 API获取经度和纬度? - How to get latitude and longitude from google maps v3 api? Google Maps API V3:如何使用从A点到B点的方向获取多个路径距离 - Google Maps API V3 : How to get multiple path distances using direction from a point A to point B Google Maps API v3:如何设置缩放级别和地图中心到用户提交的位置? - Google Maps API v3: How to Set Zoom Level And Map Center To User Submitted Location? 如何使用Google Maps JavaScript API v3获取谷歌地图中所查看区域中心的坐标 - how to get coordinates of the center of the viewed area in google maps using Google Maps JavaScript API v3 如何使用Aptana的代码帮助来使用Google Maps API v3? - How can I get Aptana's code assist to work with Google Maps API v3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM