Main
Latest
- oEmbed, flickr and starstar
- Petition Against Public Holidays
- Good Morning
- Django Apache Configuration
- Raising funds for Autism Western Cape
- When to release the code?
- Parsing Hashtags
- ISDSL International Weirdness
- Evolution a Theory?
- IPv6 in Africa
Archives
- June 2004
- July 2004
- August 2004
- September 2004
- October 2004
- November 2004
- December 2004
- January 2005
- February 2005
- March 2005
- April 2005
- May 2005
- June 2005
- July 2005
- August 2005
- September 2005
- October 2005
- November 2005
- December 2005
- January 2006
- February 2006
- March 2006
- April 2006
- May 2006
- June 2006
- July 2006
- August 2006
- September 2006
- November 2006
- December 2006
- January 2007
- February 2007
- March 2007
- April 2007
- May 2007
- June 2007
- July 2007
- August 2007
- September 2007
- October 2007
- November 2007
- December 2007
- January 2008
- February 2008
- March 2008
- April 2008
- May 2008
- June 2008
- July 2008
- August 2008
- September 2008
- October 2008
- November 2008
- December 2008
- January 2009
Google Maps and Geolocation
You can use the new google.loader.ClientLocation object to get the user's latitude and longitude and then display the user's location on an embedded map.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Google Maps and Geolocation</title>
<script type="application/javascript" src="http://www.google.com/jsapi?key=YOURKEYHERE"></script>
<script type="application/javascript">
google.load("maps", "2");
function initialize() {
var map = new google.maps.Map2(document.getElementById("map"));
if (google.loader.ClientLocation && google.loader.ClientLocation.latitude && google.loader.ClientLocation.longitude) {
document.getElementById("latitude").innerHTML = google.loader.ClientLocation.latitude;
document.getElementById("longitude").innerHTML = google.loader.ClientLocation.longitude;
map.setCenter(new google.maps.LatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude), 10);
} else {
map.setCenter(new google.maps.LatLng(0, 0), 0);
}
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<h1>Google Maps and Geolocation</h1>
<div id="map" style="width:500px;height:500px"></div>
<p>Latitude: <span id="latitude">Unknown</span></p>
<p>Longitude: <span id="longitude">Unknown</span></p>
</body>
</html>
This uses the user's source IP address; this didn't work directly from ISDSL but did work when I SSH piped through a server overseas.
I have this up on a temporary URI.
Copyright © 2004-2009 Charl van Niekerk. All articles are released under the Creative Commons Attribution 2.5 South Africa licence, unless where otherwise stated.


0 Comments
Post a Comment