Skip to content

Instantly share code, notes, and snippets.

@HaWyanHa
Created May 6, 2016 19:41
Show Gist options
  • Save HaWyanHa/ee2a5f9cebafb5adacda10ced1b170f2 to your computer and use it in GitHub Desktop.
Save HaWyanHa/ee2a5f9cebafb5adacda10ced1b170f2 to your computer and use it in GitHub Desktop.
Notes for GeoLocation
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, fail);
} else {
console.log("no html");
}
function fail (error) {
var errorType = {
0: "Unknown error",
1: "Permission denied by User",
2: "position of the user not available",
3: "Request Timed out"
};
var errMsg = errorType[error.code];
if (error.code === 0 || error.code === 2) {
errMsg = errMsg + error.message;
}
console.log(errMsg);
}
function success(position) {
var googleLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); //google maps lat lng constructor
var mapOtn = {
zoom: 10, //1-20
center: googleLatLng,//where the map has to center
mapTypeId: google.maps.MapTypeId.ROAD //satelite, roda, and hybrid
};
var Pmap = document.getElementById("map");
var map = new google.maps.Map(Pmap, mapOtn);
addMarker(map, googleLatLng, title);
console.log(position.coords.latitude, position.coords.longitude, position.coords.accuracy );
}
function addMarker(map, googleLatLng, title) {
var markerOpt = {
position: googleLatLng,
map: map,
title: title,
animation: bounce //drop
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment