Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created March 23, 2015 20:44
Show Gist options
  • Select an option

  • Save aaronksaunders/dc0ca8a6ab71b7741dc6 to your computer and use it in GitHub Desktop.

Select an option

Save aaronksaunders/dc0ca8a6ab71b7741dc6 to your computer and use it in GitHub Desktop.
longpress click hack until open issue is addressed
function map_longClick(e) {
if(OS_IOS){
var coordinate = convertPixeltoLatLng(e.x, e.y);
}
if(OS_ANDROID){
var coordinate = {latitude: e.latitude, longitude: e.longitude};
}
var a = MAP.api.createAnnotation({
latitude: coordinate.latitude,
longitude: coordinate.longitude,
title: "New Place",
pincolor: MAP.api.ANNOTATION_GREEN,
animate: true,
draggable: true
});
MAP.mapView.addAnnotation(a);
}
function convertPixeltoLatLng(x, y) {
var region = MAP.mapView.actualRegion || MAP.mapView.region;
MAP.log("debug","convertPixeltoLatLng > "+JSON.stringify(region));
var widthInPixels = MAP.mapView.rect.width;
var heightInPixels = MAP.mapView.rect.height;
var heightDegPerPixel = -region.latitudeDelta / heightInPixels;
var widthDegPerPixel = region.longitudeDelta / widthInPixels;
coordinates = {
latitude: (y - heightInPixels / 2) * heightDegPerPixel + region.latitude,
longitude: (x - widthInPixels / 2) * widthDegPerPixel + region.longitude
};
return coordinates;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment