Skip to content

Instantly share code, notes, and snippets.

@rominirani
Created July 31, 2013 03:19
Show Gist options
  • Save rominirani/6119036 to your computer and use it in GitHub Desktop.
Save rominirani/6119036 to your computer and use it in GitHub Desktop.
Episode #5 : Firefox OS Tutorial : map-app.js
$(document).ready(function(){
$("#btnLocateMe").click(function(){
findMyCurrentLocation();
});
});
function findMyCurrentLocation(){
var geoService = navigator.geolocation;
if (geoService) {
navigator.geolocation.getCurrentPosition(showCurrentLocation,errorHandler,{enableHighAccuracy:true});
} else {
alert("Your Browser does not support GeoLocation.");
}
}
function showCurrentLocation(position){
console.log(position.coords.latitude + "," + position.coords.longitude);
//Create the latlng object based on the GPS Position retrieved
var latlng = new google.maps.LatLng (position.coords.latitude, position.coords.longitude);
//Set Google Map options
var options = {
zoom : 15,
center : latlng,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
var $content = $("#map-page div:jqmData(role=content)");
//Set the height of the div containing the Map to rest of the screen
$content.height(screen.height - 50);
//Display the Map
var map = new google.maps.Map ($content[0], options);
//Change to the map-page
$.mobile.changePage ($("#map-page"));
//Create the Marker and Drop It
new google.maps.Marker ({ map : map,
animation : google.maps.Animation.DROP,
position : latlng
});
}
function errorHandler(error){
alert("Error while retrieving current position. Error code: " + error.code + ",Message: " + error.message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment