The location API example is PS 1.0 style, which is just slightly harder to use compared to PS 2.0 location API. But as you already got PS 1.0 version working, there is no real need to switch to PS 2.0. Actually PS 2.0 platformservices.js only wraps the PS 1.0 API.
Anyhow here is the PS 2.0 location API example if you want to test it out.
Code:
*
* Geolocation service object based on com.nokia.device.geolocation Interface
*/
var geolocation_so = null;
/*
* Initializes geolocation service object
*/
function initGeolocation(){
try {
geolocation_so = nokia.device.load("geolocation");
}
catch (e) {
if (e.message == "security access check failed") {
alert("Access to location service was not granted");
}
else {
alert(e);
}
}
}
/**
* Error Callback
* @param {PositionError} result
*/
function location_SingleShot_error_callback(result){
alert('Error retrieving position\ncode :' + result.code + '\nmessage: ' + result.message);
}
/**
* Callback function that is called with positionInformation when
* location is obtained successfully
* @param {Position} position
*/
function location_SingleShot_callback(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("Lat: " + latitude + "\nLong: " + longitude );
}
/**
* Retrieves the current geographic location of the device
*/
function getLocationSingleShot(){
//see PositionOptions object
var positionOpts = {
enableHighAccuracy : false,
timeout: 120000, //GPS timeout in ms, 120000 (2min) is recommended
maximumAge: 60000 //Enables the use of cached location. Must be less than timeout
//Special values: 0 always new, Infinity to retrieve last known position.
};
try {
geolocation_so.getCurrentPosition(location_SingleShot_callback, location_SingleShot_error_callback, positionOpts);
}catch (e) {
var error = e.toString();
alert(error);
}
}
-Ilkka