Using the same technology and generalised geo.js API as the first Where am I article, the code behind this page first retrieves the lat/long coordinates and then also feeds them into a Google map. If all went well and you didn't decline your browser's request to share your geographic position, you should see your location (or that of your service provider) marked on the map below.
Click the marker to see your lat/long coordinates. Pretty impressive, huh? And so easy to do.... if you don't mind fiddling with javascript...
But guess what? You don't have to. You can so easily produce maps like these on your Drupal site without writing any code and still retain full configuration control over the look and feel. Just download the IP Geolocation module and you're away.
<script src="http://geo-location-javascript.googlecode.com/svn/trunk/js/geo.js"></script> <script src="http://maps.google.com/maps/api/js?sensor=false"></script> <script> if (geo_position_js.init()) { geo_position_js.getCurrentPosition(displayMap, displayError, {enableHighAccuracy: true}); } else { alert("Error: geo_position_js is not available."); } var mapOptions = { zoom: 16, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map-wrapper"), mapOptions); function displayMap(position) { var coords = position.coords; var you = new google.maps.LatLng(coords.latitude, coords.longitude); var marker = new google.maps.Marker({ map: map, position: you}); map.setCenter(you); var infoPopUp = new google.maps.InfoWindow({ content: "Yes that should be you at latitude " + coords.latitude + ", longitude " + coords.longitude + " (accuracy: " + coords.accuracy + " meters)" }); google.maps.event.addListener(marker, 'click', function() { infoPopUp.open(map,marker) }); } function displayError(error) { alert("Error code: " + error.code); } </script>