Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw line on Map View given coordinates?

How to draw line on MapView given coordinates?

AFAIK, on iPhone it is possible.

Please advise.

Thanks in advance.

like image 254
AndroiDBeginner Avatar asked Dec 20 '09 23:12

AndroiDBeginner


People also ask

Can you draw lines on Google Maps app?

Can you draw a grid on Google Maps? It is not possible to show the latitude and longitude lines on Google Maps, but you can do that on Google Earth. In a web browser or on the Google Earth app, go to Settings > Map Style > Enable Gridlines.

Can you draw a path on maps?

You can trace a path or highlight an area on your map by drawing lines and shapes.

How do you draw a line with coordinates on Google Earth?

You can enter latitude/longitude coordinates into search in Google My Maps or Google Earth Pro and the program will fly to that location and place a pin. The exact location should be the tip of the pin for many icons. The center for others. Then you can draw lines between the points.


1 Answers

To use a MapView your Activity must extend MapActivity.

For each line you want to draw (or really anything else) you need to subclass Overlay and do the drawing in the Overlay's onDraw() method. Once you've created your Overlay add it to the MapView with something like mMapView.getOverlays().add(new MyOverlay());.

Inside your custom Overlay you'll want to get a Projection with something like Projection p = mapView.getProjection();. From the Projection you can convert GPS coordinates into screen coordinates with Projection's toPixels(GeoPoint, Point) method and then just draw to the passed in Canvas using normal Android 2D drawing methods.

That's the basics... if you need anything else, just ask.

like image 145
Jeremy Logan Avatar answered Oct 15 '22 09:10

Jeremy Logan