×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - Converting a map screen pixel to a geo coordinate

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Automated change of category from Ovi Maps to Nokia Maps)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot addition of Template:ArticleMetaData)
Line 1: Line 1:
 +
{{ArticleMetaData
 +
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|id= <!-- Article Id (Knowledge base articles only) -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by=<!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate=20110621
 +
|author=[[User:Maveric]]
 +
}}
 +
 
[[Category:Web]][[Category:Browser]][[Category:Nokia Maps]]
 
[[Category:Web]][[Category:Browser]][[Category:Nokia Maps]]
 
==Introduction==
 
==Introduction==

Revision as of 02:47, 2 January 2012

Article Metadata
Article
Created: Maveric (21 Jun 2011)
Last edited: hamishwillee (02 Jan 2012)

Contents

Introduction

In this article we will go thru how to convert map screen to a geocoordinate. This is useful when we want to know the geocoordinates of the point user had clicked.

Prerequisites

Ovi Maps API supported web browser (basically any modern web browser)The example assumes you have already added the Ovi Maps to your web page as explained in the previous article "Ovi Maps - Add Map To Any Page".

Important about Maps credentials

With Ovi Maps API you can start without having any credentials given, but you might face a performance gap. In order to get the full potential out of the offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.For more information on how to obtain the credentials, please start with the Ovi Maps API Developers Guide section "Acquiring API credentials"

Implementation

To achieve what we are about to do, we will need to use a method called pixelToGeo, definition below:

pixelToGeo (coord) : ovi.mapsapi.geo.Coordinate - this will translate a projected pixel coordinate into a GEO Coordinate.

We also need to use the EventListener and addListener method, which is defined by the Ovi Maps API reference as follows:addListener (type, listener, useCapture) ObjectRegisters an event listener, depending on the useCapture parameter, on the capture phase of the event flow or itstarget and bubbling phases.

Parameters: {String} type Specifies the event type associated with the event for which the user is registering. {Function} listener The function to be called if the event occurs.

Example code

This example will add a new eventListener on the map and register the "click" event to fire the function "eventListener". We will get the position user had clicked and this will be converted from pixel projection coordinate to a geocoordinate. The result is sent to screen with JavaScript Alert function.

<html>
<head>
<title>Pixel to geocoordinate</title>
<script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="map" style="z-index: -1; left:0px; top:0px; width: 100%; height: 100%; position: absolute;"></div>
<script type="text/javascript">
 
// Set the authentication token, which is needed by the web-services to authenticate your application.
ovi.mapsapi.util.ApplicationContext.set("authenticationToken", "<Token>");
 
var map = new ovi.mapsapi.map.Display(document.getElementById("map"), {'zoomLevel':4, 'center':[53.1, 15.1]});
 
var clicked_location = "";
var myContainer;
 
map.addListener("click", eventListener); // add the listener for mouse click
 
map.set("baseMapType", map.NORMAL);
 
function eventListener(event){
alert("in EventListener");
clicked_location = map.pixelToGeo(event.displayX, event.displayY);
 
alert(clicked_location.toString());
alert("Adding a Marker there");
add_Marker_where_clicked();
}
 
 
function add_Marker_where_clicked(){
 
myMarker = new ovi.mapsapi.map.Marker(clicked_location);
 
map.objects.add(myMarker);
 
}
</script>
</body>
</html>

For more on Ovi Maps API

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

http://api.maps.ovi.com

Tested with

Google Chrome 11.0x

Mozilla Firefox 5.0

For more on Ovi Maps API

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

http://api.maps.ovi.com

Tested on

Google Chrome 11.0x

Mozilla Firefox 5.0

244 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×