Blog

Where are you? Geo Location in HTML 5

| 0 comments | html5

My latest little web application (doesn't actually really do anything yet) now finds out, as close as possible, where you are!

The Location Page will get your browser to ask for your permission to tell it where abouts you are. The spec can be found here. The piece of code I use is quite simply:

<script>
$(document).ready(function(){
var latlong;
function error(msg) {
alert(msg);
}
function success(position) {
latlong = position.coords.latitude +","+ position.coords.longitude;
$("#location").html(<img src="http://maps.google.com/maps/api/staticmap?center="+latlong+"&zoom=15&size=600x600&maptype=roadmap&sensor=false&markers=color:blue|label:A|"+latlong+"" title="You are here" alt="Map">");
}
navigator.geolocation.getCurrentPosition(success, error);
});
</script>

This piece of javascript not only requests the location from the browser but then, on success, updates the page with a static map from Google with a marker of your returned latitude and longitude.

Examples of use for this API would be local data, weather, news etc that could all take precedence on a page


Comments

Be the first to comment!

Add a comment