Skip to content

Instantly share code, notes, and snippets.

@kennethkalmer
Last active January 3, 2016 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennethkalmer/8429314 to your computer and use it in GitHub Desktop.
Save kennethkalmer/8429314 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<style type="text/css">
#loading p {
color: #373737;
text-align: center;
font-size: 20px;
}
</style>
<div id="loading">
<p>Loading...</p>
</div>
<script src="jsbin.uBEviyut.js"></script>
</body>
</html>
stubDeviceReady = true;
Modernizr.load([
{
load: "https://js.cit.api.here.com/ee/2.5.3/jsl.js?blank=true",
complete: function() {
if (!nokia && !nokia.maps) {
alert('Failed to load maps');
return;
}
nokia.Settings.set("app_id", "DemoAppId01082013GAL");
nokia.Settings.set("app_code", "AJKnXv84fjrb0KIHawS0Tg");
// Use staging environment (remove the line for production environment)
nokia.Settings.set("serviceMode", "cit");
// Load the geolocation support first
console.log("Loading positioning & search");
nokia.Features.load( { "positioning": "auto", "search": "auto" }, function() {
// Geolocate the user as quickly as possible
console.log("Loaded positioning and search features");
var success = function(position) {
console.log("Position loaded: ", position);
// Feedback
$('#loading p').text('Device located...');
// Reverser geocode the position to get an address
var searchManager = new nokia.maps.search.Manager();
var processResults = function (manager, key, newValue, oldValue) {
switch (newValue) {
case "initial":
case "started":
case "cleared":
break;
case "finished":
console.log("Got address: ", manager.locations[0]);
break;
default:
console.warn("Failed to get address of visitor");
}
};
var coords = position.coords;
searchManager.addObserver("state", processResults);
searchManager.reverseGeocode( coords );
};
var err = function(error) {
console.error("Position failed: ", error);
// feedback
$('#loading p').text('Device could not be located...');
};
// Get the current position of the user
var geolocate = function() {
var positioning = new nokia.maps.positioning.Manager();
positioning.getCurrentPosition( success, err );
};
if ( stubDeviceReady ) {
geolocate();
} else {
window.addEventListener('deviceready', geolocate);
}
// Feedback
$('#loading p').text('Locating your device...');
}, function(err) {
console.error( "Failed to load nokia.maps or nokia.search: ", err);
});
// Load the rest of the features
console.log("Loading map, routing, behavior, ui");
nokia.Features.load({
"map": "auto",
"routing": "auto",
"behavior": "auto",
"ui": "auto"
}, function() {
console.log("Loaded extended map dependencies");
}, function(err) {
console.error("Failed to load nokia.map, nokia.routing, nokia.behavior or nokia.ui:", err);
});
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment