HERE Maps API - How to check the Date Border Crossing
This article explains how to check the Date Border Crossing using the HERE Maps API.
Contents |
Introduction
The isCDB flag of the BoundingBox in HERE Maps API has been added since v2 to indicate that the bounding box is crossing the date border. A bounding box which is spanned from -180° (left) to +180° (right) is NOT crossing the date border. Default value is false.
The API reference link: http://developer.here.net/docs/maps_js/topics_api_pub/nokia.maps.geo.BoundingBox.html#topic-apiref__BoundingBox-isCDB
The International Date Line (IDL) Definition by Wikipedia.org
IDL is a generally north-south imaginary line on the surface of the Earth, passing through the middle of the Pacific Ocean, that designates the place where each calendar day begins. It is roughly along 180° longitude, opposite the Prime Meridian, but it is drawn with diversions to pass around some territories and island groups.Crossing the IDL traveling east results in a day or 24 hours being subtracted, so that the traveler repeats the date to the west of the line. Full description here: http://en.wikipedia.org/wiki/International_Date_Line
Example code
This example first adds two Markers for which the BoundingBox is not crossing the International Date Line. A third Marker is then randomly added to coordinates that will cause the check to produce the BoundingBox to have crossed the IDL. Remember to add in your own AppId and Token to get the example to work.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Check for Date Border Crossing</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript"
src="http://api.maps.nokia.com/2.2.4/jsl.js" charset="utf-8">
</script>
</head>
<body>
<div id="mapContainer" style="z-index: -1; left:0px; top:0px; width: 100%; height: 80%; position: absolute;"></div>
<script type="text/javascript">
/////////////////////////////////////////////////////////////////////////////////////
// Don't forget to set your API credentials
//
// Replace with your appId and token which you can obtain when you
// register on http://api.developer.nokia.com/
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
//
/////////////////////////////////////////////////////////////////////////////////////
var map = new nokia.maps.map.Display(document.getElementById("mapContainer"),
{ components: [ new nokia.maps.map.component.Behavior()],
'zoomLevel': 10,
'center':[-1.366667, 176.466667]
}
);
var markerContainer = new nokia.maps.map.Container()
markerContainer.objects.add(
new nokia.maps.map.StandardMarker
(
[-1.366667, 176.466667],
{
text: "-1.366667, 176.466667",
draggable: false
}));
markerContainer.objects.add(
new nokia.maps.map.StandardMarker(
[-1.366667, 180.000000],
{
text: "-1.366667, 180.000000",
draggable: false,
}));
map.objects.add(markerContainer);
map.zoomTo(markerContainer.getBoundingBox(),false,true);
// Check for Date Border Crossing
checkDateBorder();
// Add new Marker randomly
markerContainer.objects.add(
new nokia.maps.map.StandardMarker(
[Math.random() * 180 - 90, -176.000],
{ text: "-176.000, 179.000",
draggable: false,
}));
map.zoomTo(markerContainer.getBoundingBox(),false,true);
// Check for Date Border Crossing
checkDateBorder();
function checkDateBorder()
{
var CDB = markerContainer.getBoundingBox().isCDB;
if (CDB == false)
{
alert("False - The Bounding box is not crossing the date border");
} else if(CDB == true)
{
alert("True - The Bounding box crosses the date border");
}
}
</script>
</body>
</html>
For more on HERE Maps API
Please check out the HERE Maps API full documentation and API reference here:
You may also access the interactive API explorer


Hamishwillee - When it this likely to be completed?
When done, please remove draft category and add proper categories.hamishwillee 02:36, 18 November 2011 (EET)
Out of Draft as of today. //Maveric
Hamishwillee - Thanks
I removed the draft category. Are there any of the other fields in the ArticleMetaData with relevance? For example, is there a particular version of Nokia Maps API that this is dependent on?hamishwillee 01:41, 22 November 2011 (EET)