简体   繁体   中英

Android Maps V2 metersToEquatorPixels where/what is the equivalent in new maps?

Android Maps had this nice little method on the projection for a map, MetersToEquatorPixels that let you convert between pixels and meters at the equator, and then a quick little multiplication of that result by *(1/Math.cos(Math.toRadians(latitudeofmap) would tell you how many pixels would represent the equivalent for that latitude.

What the heck is the equivalent in Maps V2? If I want to say, draw a legend, to show distance, I have to know how much distance each pixel represents in lat/lon distance, and since this method is now gone, I have no idea how the heck I can get this... So what is the equivalent in V2?

Maybe it can help you: I take it from: https://gist.github.com/amay077/6879638

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);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM