javascript - How to get the user's location from iPhone using Google Maps API v3? - Stack Overflow

I want to make a google map on the iPhone and show the user's location when they first open the si

I want to make a google map on the iPhone and show the user's location when they first open the site.

But i can't find this method on Google Maps v3 api. So i think maybe the iPhone has the function to do this. Does it?

I want to make a google map on the iPhone and show the user's location when they first open the site.

But i can't find this method on Google Maps v3 api. So i think maybe the iPhone has the function to do this. Does it?

Share Improve this question edited Sep 14, 2010 at 10:28 Daniel Vassallo 345k72 gold badges513 silver badges446 bronze badges asked Jul 22, 2010 at 1:28 zjm1126zjm1126 67k86 gold badges179 silver badges222 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You may want to use the W3C Geolocation API, which Safari on the iPhone supports.

Plotting a point on Google Maps using the position from the Geolocation API, will look something like this:

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:

<script src="http://maps.google./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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745441834a4627865.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信