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?
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.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>