Consider utilizing the W3C Geolocation API, which is supported by Safari on the iPhone.
To display a point on Google Maps using data from the Geolocation API, the code will resemble this:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var point = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
// Set up Google Maps API v3
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: point,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Add a marker
new google.maps.Marker({
position: point,
map: map
});
});
}
else {
alert('W3C Geolocation API is not available');
}
Ensure that Google Maps API v3 is included in your webpage:
<script src="http://maps.google.com/maps/api/js?sensor=true"
type="text/javascript"></script>
... and have a placeholder for the map area:
<div id="map" style="width: 500px; height: 400px;"></div>