NKMapView
Overview
This class is used to display google map in your application
init(x,y,width,height)
initializes map view with given width, height and coordinates on webview
show()
shows initialized map view
hide()
hides initialized map view
showUserlocation()
triggers core location services to track user location and show it on the map, can take parameters "yes" or "no"
setMapType()
sets the map type, can take parameters "standard", "satellite", "hybrid"
getUserLocation(callback)
retrieves current user location, takes callback parameter of format "callback(newLocation)", new location returned as callback argument
isUserLocationUpdating()
indicates if CoreLocation is turned on to update user location, returns "1" or "0"
setDisplayRegion(lat, longtitude, latDelta, longtitudeDelta)
scrolls the map so specified location could be visible in span
latitudeDelta
The amount of north-to-south distance (measured in degrees) to use for the span.
Unlike longitudinal distances, which vary based on the latitude, one degree of latitude is
approximately 111 kilometers (69 miles) at all times.
longitudeDelta
The amount of east-to-west distance (measured in degrees) to use for the span. The
number of kilometers spanned by a longitude range varies based on the current
latitude. For example, one degree of longitude spans a distance of approximately 111
kilometers (69 milies) at the equator but shrinks to 0 kilometers at the poles.
addAnnotation(lat, longitude, title, subtitle, image, color, callback)
adds marker on the map on given coordinates with specified title and subtitle color is an index of standard colors for annotation pin, can take 3 values [0..2], callback is a javascript function name to be called when user taps on annotation pin. Image can be either bundled image name or NKImage object instance.
selectAnnotation(title)
selects annotation with the title specified when annotation was added, do not use this method directly after annotation was added as it has no time to initialize, use setTimeout function to select annotation after a small delay like half a second.
setDelegateCallback(callback)
sets delegate callback to be called when map is loading, loaded or failed to load. The callback format is following "callback(state)", where state can take following values: 0 for loading, 1 for loaded and -1 if loading failed
clearAnnotations()
removes all annotations added to the map previously
getDisplayRegion()
returns display region which is visible to the user at the moment, the region returned as a string with 4 components divided by comma: center longitude, center latitude, span longitude delta and span latitude delta, for example: "102.122,34.65,12.1,2.06"
setCenterCoordinate(latitude, longitude, isAnimated)
Changing the center coordinate centers the map on the new coordinate without changing the current zoom level. It also updates the values in the region property to reflect the new center coordinate and the new span values needed to maintain the current zoom level.
Callbacks:
mapTouchedAtCoordinates(latitude, longitude)
Implement this callback on the page where NKMapView was created and it will be called automatically every time user touches the map returning latitude and longitude as callback parameters. If you donʼt need user input just ignore this callback and don't implement it.
Example:
//example 1:
map.init(0, 100, 320, 460);
lat = 50;
lon = 30;
map.setDisplayRegion(lat, lon, 0.007435, 0.003130);
map.showUserLocation("YES");
map.addAnnotation(lat, lon, "Here", "subtitle");
map.show();
setTimeout(selectAnnotation, 500); //wait for half second
function selectAnnotation()
{
map.selectAnnotation('Here');
}
// example 2:
var oldLocation = "0.000000 0.000000 0.000000 0.000000";
var mapView = new NKMapView();
mapView.init(0, 0, 320, 420);
mapView.showUserLocation("YES");
checkIfUpdated();
function checkIfUpdated()
{
mapView.getUserLocation("alertLocation");
}
function alertLocation(newLocation){
if (newLocation != oldLocation){
oldLocation = newLocation;
var location = new Array();
location = newLocation.split(" ");
// now location is an array with 4 elements: x, y, precision and speed
}
else
setTimeout(checkIfUpdated, 1000);
}
function mapTouchedAtCoordinates(latitude, longitude)
{
NKLog("Latitude: "+latitude+"Longitude: "+longitude);
}

