Namespaces
Variants
Actions
Revision as of 15:24, 3 January 2013 by jasfox (Talk | contribs)

Locate user with HERE Maps API internal positioning method

Jump to: navigation, search

This article demonstrates how to show the user's location on Nokia Maps using the Nokia Maps API built-in method. Not only will it get the position, but puts a marker on that place and also shows an uncertainty circle around the position.

MultiMediaTile.png
Article Metadata

Compatibility
Platform(s): Web browser
Dependencies: Nokia Maps 2.2.3

Article
Keywords: Nokia Map, JavaScript, geolocation
Created: Maveric (29 Dec 2010)
Updated: avnee.nathani (31 Dec 2011)
Last edited: jasfox (03 Jan 2013)

Contents

Prerequisites

This example requires a supported browser and the user to accept or already permanently have accepted geolocation requests from the browser.

Implementation

This article consists of one file that has all the required HTML and JavaScript code.

"index.html"

The HTML part will load the Nokia Maps API JavaScript, defines a div for the Nokia Maps to be displayed and then execute the initialize function (init) of our script file. If needed, modify the paths and name of the file to suite your purposes.


Example code

HTML file ”index.html”

<!-- This example shows Nokia Maps with a marker on location retrieved using Nokia Maps API internal method-->
<html>
<head>
<script type="text/javascript"
src="http://api.maps.nokia.com/2.2.3/jsl.js" charset="utf-8">
</script>
</head>
<body onload="init()">
<center>
<div id="map" style="width:640px; height:360px;"></div>
</center>
 
<script type="text/javascript">
var map;
var marker;
var my_latitude;
var my_longitude;
var positioning;
var coords;
 
function init(){
// Don't forget to set your API credentials
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
 
alert ("Note: Please accept the location request from your browser in order to view your location on the Nokia Maps.");
map = new nokia.maps.map.Display(document.getElementById("map"),
{
components: [ new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Overview(),
new nokia.mapsi.map.component.TypeSelector(),
new nokia.maps.map.component.ScaleBar() ],
zoomLevel: 3,
center: [52.51, 13.4] // default map center point (not the location retrieved)
 
});
 
positioning = new nokia.maps.positioning.Manager();
positioning.getCurrentPosition(
 
function(position) {
coords = position.coords;
showMyPosition(coords);
}
);
}
 
function showMyPosition(p)
{
 
var marker = new nokia.maps.map.StandardMarker(p);
var accuracyCircle = new nokia.maps.map.Circle(p, p.accuracy);
map.objects.addAll([accuracyCircle, marker]);
map.zoomTo(accuracyCircle.getBoundingBox(), false, "default");
}
 
</script>
</body>
</html>

For more on the Nokia Maps API

Please check out the Nokia Maps API full documentation and API reference here:

You may also access the interactive API explorer

410 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved