Maps distance calculus

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

Maps distance calculus

Postby Malefico » Tue Nov 18, 2008 9:15 am

I need an help :shock:

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
Developer
 
Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Top

Postby lesha_aw » Thu Nov 20, 2008 7:24 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.  
  46.                         mPixRadius=myMapView.getProjection().metersToEquatorPixels(mRadius);
  47.  
  48.  
  49.  
  50.                         canvas.drawCircle(myScreenCoords.x, myScreenCoords.y, mPixRadius, paint);
  51.  
  52.                         return true;
  53.  
  54.                 }
  55.  
  56.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


do anybody know anything about "onZoom" event ?
lesha_aw
Freshman
Freshman
 
Posts: 8
Joined: Wed Nov 19, 2008 8:57 pm

Postby Malefico » Fri Nov 21, 2008 11:55 am

:shock:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  mPixRadius=myMapView.getProjection().metersToEquatorPixels(mRadius);
Parsed in 0.031 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
Developer
 
Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Postby Malefico » Fri Nov 21, 2008 12:10 pm

Malefico wrote::shock:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  mPixRadius=myMapView.getProjection().metersToEquatorPixels(mRadius);
Parsed in 0.034 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
Developer
 
Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Postby lesha_aw » Sat Nov 22, 2008 12:41 pm

:shock:

Java:
mPixRadius=myMapView.getProjection().metersToEquatorPixels(mRadius);


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
Freshman
 
Posts: 8
Joined: Wed Nov 19, 2008 8:57 pm

Postby Malefico » Mon Nov 24, 2008 9:19 am

lesha_aw wrote:
:shock:

Java:
mPixRadius=myMapView.getProjection().metersToEquatorPixels(mRadius);


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 :idea:
Malefico
Developer
Developer
 
Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Top

Postby lesha_aw » Mon Nov 24, 2008 8:39 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

mPixRadius=(myMapView.getProjection().metersToEquatorPixels(mRadius) * (1/ Math.cos(Math.toRadians(mlatitude))));

I test it in some objects. It seems it works. But may be it is mistake?
lesha_aw
Freshman
Freshman
 
Posts: 8
Joined: Wed Nov 19, 2008 8:57 pm

Postby dmt » Thu Jan 08, 2009 2:49 am

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.
User avatar
dmt
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Jan 05, 2009 6:06 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 1 guest