Geolocation example.


JavaScript Demo Source: nokia-geolocation.js

var	map;
var	geolocator;

function initialize() {
	map = new nokia.maps.map.Display(
		document.getElementById("map"),
		{
	    	'zoomLevel': 8,
	    	'center': [52.530390, 13.385190],
			components: [ 
				new nokia.maps.map.component.Behavior(),
				new nokia.maps.map.component.ZoomBar()
			]
		});
		
	if (nokia.maps.positioning.Manager) {
		geolocator = new nokia.maps.positioning.Manager();
		
		geolocator.getCurrentPosition(geolocation_success_callback, geolocation_error_callback);
	}
	
	else {
		alert ("Geolocation is not currently supported in this browser");
	}
}

function geolocation_success_callback(position) {
	var	coords = position.coords;
	var	marker = new nokia.maps.map.StandardMarker(coords);
	var	accuracy = new nokia.maps.map.Circle(coords, coords.accuracy);
	
	map.objects.addAll([accuracy, marker]);
	map.zoomTo(accuracy.getBoundingBox(), false, "default");
	if (map.zoomLevel > 16) {
		map.set("zoomLevel", 16);
	}
}

function geolocation_error_callback(error) {
	var errorMsg = "Location could not be determined: ";

	if(error.code == 1) errorMsg += "PERMISSION_DENIED";
	else if(error.code == 2) errorMsg += "POSITION_UNAVAILABLE";
	else if(error.code == 3) errorMsg += "TIMEOUT";
	else errorMsg += "UNKNOWN_ERROR";

	alert(errorMsg);	
}