## Maps distance calculus

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

### Maps distance calculus

I need an help

I have a GeoPoint.. i have a radius in km.. and i want to draw a circle on a map.

Obviously its dimension depends on Zoom level.

I need the ratio beetween pixel and km in each zoom level or a another geopoint exacly at the radius distance ( so i can calculate the distance in pixel ).
Malefico
Developer

Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

look here http://blog.pocketjourney.com/2008/03/1 ... p-windows/
- usefull tutorial

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
1.
2.         protected class MyLocationOverlay extends com.google.android.maps.Overlay {
3.
4.
5.
6.                 @Override
7.
8.                 public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
9.
10.                                 long when) {
11.
12.
13.
14.                         // Setup our "brush"/"pencil"/ whatever...
15.
16.                         Paint paint = new Paint();
17.
18.
19.
20.                         super.draw(canvas, mapView, shadow);
21.
22.                         // Converts lat/lng-Point to OUR coordinates on the screen.
23.
24.                         GeoPoint point = new GeoPoint(
25.
26.                                         (int) (mlatitude.doubleValue() * 1000000),
27.
28.                                         (int) (mlongitude.doubleValue() * 1000000));
29.
30.                         Point myScreenCoords = new Point();
31.
32.                         mapView.getProjection().toPixels(point, myScreenCoords);
33.
34.
35.
36.                         paint.setStrokeWidth(3);
37.
38.                         paint.setARGB(80, 0, 0, 255);
39.
40.                         paint.setStyle(Paint.Style.STROKE);
41.
42.
43.
44.                         //may be this operation must be in zoom event, but i didn't find such event
45.
47.
48.
49.
50.                         canvas.drawCircle(myScreenCoords.x, myScreenCoords.y, mPixRadius, paint);
51.
52.                         return true;
53.
54.                 }
55.
56.
Parsed in 0.013 seconds, using GeSHi 1.0.8.4

do anybody know anything about "onZoom" event ?
lesha_aw
Freshman

Posts: 8
Joined: Wed Nov 19, 2008 8:57 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
Parsed in 0.011 seconds, using GeSHi 1.0.8.4

its Perfect!

One line against my randiant and geometrical calculus!

i dont know if there is an onZoom event.. if metersToEquatorPixels() is to heavy you can check if the zoom level is the same or not.. and call this method only if it is changed.
Malefico
Developer

Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Malefico wrote::shock:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
Parsed in 0.011 seconds, using GeSHi 1.0.8.4

its Perfect!

One line against my randiant and geometrical calculus!

i dont know if there is an onZoom event.. if metersToEquatorPixels() is to heavy you can check if the zoom level is the same or not.. and call this method only if it is changed.

i try this.. but it isnt a good solution because during the zoom animation the circle dont resize.
Malefico
Developer

Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Java:

its Perfect!

One line against my randiant and geometrical calculus!

but it work correctly only on equator! In any other place radius of circle will be less when you want!
lesha_aw
Freshman

Posts: 8
Joined: Wed Nov 19, 2008 8:57 pm

lesha_aw wrote:

Java:

its Perfect!

One line against my randiant and geometrical calculus!

but it work correctly only on equator! In any other place radius of circle will be less when you want!

yes...

but a real calculus is to complicated for me now.. i use a little costant to correct this distance for the italy latitude
Malefico
Developer

Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Android Documentation:

public float metersToEquatorPixels(float meters)

Converts a distance in meters (along the equator) to one in (horizontal) pixels at the current zoomlevel. In the default Mercator projection, the actual number of pixels for a given distance will get higher as you move away from the equator.

wiki (about Mercator projection):
http://en.wikipedia.org/wiki/Mercator_projection

The scale is proportional to the secant of the latitude φ

So, i use it like

I test it in some objects. It seems it works. But may be it is mistake?
lesha_aw
Freshman

Posts: 8
Joined: Wed Nov 19, 2008 8:57 pm

Are you sure your secant scaling function *faithfully* distorts the original fn output *everywhere* in the function domain? Or is it correct simply at your two endpoints?

If not, perhaps you can try computing a haversine fn on the two coordinates, then use that to compute the distance between the two points, then you can construct your circle from that. This way, your circle will be completely independent of your position relative to the equator.

dmt
Junior Developer

Posts: 15
Joined: Mon Jan 05, 2009 6:06 am