Created
October 8, 2013 04:55
-
-
Save amay077/6879638 to your computer and use it in GitHub Desktop.
metersToEquatorPixels を Google Maps Android API v2 で ref: http://qiita.com/amay077/items/1a0acfe09a2e915a8658
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
| public static int metersToEquatorPixels(GoogleMap map, LatLng base, float meters) { | |
| final double OFFSET_LON = 0.5d; | |
| Location baseLoc = new Location(""); | |
| baseLoc.setLatitude(base.latitude); | |
| baseLoc.setLongitude(base.longitude); | |
| Location dest = new Location(""); | |
| dest.setLatitude(base.latitude); | |
| dest.setLongitude(base.longitude + OFFSET_LON); | |
| double degPerMeter = OFFSET_LON / baseLoc.distanceTo(dest); // 1m は何度? | |
| double lonDistance = meters * degPerMeter; // m を度に変換 | |
| Projection proj = map.getProjection(); | |
| Point basePt = proj.toScreenLocation(base); | |
| Point destPt = proj.toScreenLocation(new LatLng(base.latitude, base.longitude + lonDistance)); | |
| return Math.abs(destPt.x - basePt.x); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment