Created
March 23, 2015 20:44
-
-
Save aaronksaunders/dc0ca8a6ab71b7741dc6 to your computer and use it in GitHub Desktop.
longpress click hack until open issue is addressed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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