Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

android - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...