Android
구글맵 맵상에서 거리구하기
Leo 리오
2010. 11. 24. 01:48
반응형
지구는 둥구니까
지도상에서 거리구하는것이 아주 복잡하다.
Area(GeoPoint c,GeoPoint r)
{
this.c = c; this.r= r;
Location lc = new Location("gps"); lc.setLatitude(c.getLatitudeE6()/1E6); lc.setLongitude(c.getLongitudeE6()/1E6);
Location lr = new Location("gps"); lr.setLatitude(r.getLatitudeE6()/1E6); lr.setLongitude(r.getLongitudeE6()/1E6);
radius = lc.distanceTo(lr);
}
distanceTo함수를 사용하면 미터 단위로 값이 나오게된다.
그런데 구글맵에서는 확대 축소가 가능하기때문에 미터단위가 아닌 픽셀단위의 값이 있어야 맵상에서 거리를 표현가능하다.
mapView.getProjection().metersToEquatorPixels(meters);
그런데 이렇게 나타내면 오묘하게 다르게 나온다.
역시 지구는 둥구니까
(mapView.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))
를 이용하면 정확하게 두 지점사이의 거리를 맵상에서 나타낼 수 있다.
지도상에서 거리구하는것이 아주 복잡하다.
Area(GeoPoint c,GeoPoint r)
{
this.c = c; this.r= r;
Location lc = new Location("gps"); lc.setLatitude(c.getLatitudeE6()/1E6); lc.setLongitude(c.getLongitudeE6()/1E6);
Location lr = new Location("gps"); lr.setLatitude(r.getLatitudeE6()/1E6); lr.setLongitude(r.getLongitudeE6()/1E6);
radius = lc.distanceTo(lr);
}
distanceTo함수를 사용하면 미터 단위로 값이 나오게된다.
그런데 구글맵에서는 확대 축소가 가능하기때문에 미터단위가 아닌 픽셀단위의 값이 있어야 맵상에서 거리를 표현가능하다.
mapView.getProjection().metersToEquatorPixels(meters);
그런데 이렇게 나타내면 오묘하게 다르게 나온다.
역시 지구는 둥구니까
(mapView.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))
를 이용하면 정확하게 두 지점사이의 거리를 맵상에서 나타낼 수 있다.
결과
반응형