Skip to content

Instantly share code, notes, and snippets.

@amay077
Created October 8, 2013 04:55
Show Gist options
  • Select an option

  • Save amay077/6879638 to your computer and use it in GitHub Desktop.

Select an option

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
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