Thursday, April 30, 2009

Google Location Services now in Mozilla Firefox

With recent launches like Google Latitude and Google Toolbar with My Location, it's clear we think location-based services are useful and fun! We also want developers everywhere to be able to use location to build cool new features and applications.

I'm pleased to announce that Google's Location Service (the same service which powers the My Location feature in many Google products), is now the default location provider in Mozilla Firefox 3.5 beta 4. This means that developers can, with users' permission, gain access to their approximate location without requiring any additional plug-ins or setting configurations. It just works!

Mozilla Firefox 3.5 beta 4 uses the W3C geolocation API, a standard being adopted by many major browsers, so you won't have to branch code in the future.

For web developers, using geolocation services in Firefox is easy! Here's a simple example to get you started:
<html>
<head>
<script type="text/javascript">

function displayLocation(loc) {
var locDiv = document.getElementById("locationDiv");
locDiv.innerHTML = "lat: " + loc.coords.latitude + ", lon:" + loc.coords.longitude;
}

function getLocation() {
navigator.geolocation.getCurrentPosition(displayLocation);
}

</script>
</head>

<body>
<a href="#" onClick="getLocation()">Click here to display location</a><br>
<div id="locationDiv"></div>
</body>
</html>
When your site calls getCurrentPosition, a drop down will ask the user permission to get his or her location. Upon acceptance of the request, the callback function you specify will run with the machine's approximate location contained in the loc parameter. Here's a screenshot of the permission dropdown:


We hope you find the new and useful ways to use the new geolocation capabilities of Firefox!

No comments:

Post a Comment