Discussion:
Draw Polygon on Maps
Peter
2010-01-13 13:29:28 UTC
Permalink
Hi,

I am new to Android Dev and to this group. I wanted to do some work
with the MapView. Mostly some basic stuff like zooming to an address,
and the programatically drawing a shape (polygon) based on user input
of coordinates. Then i want to overlay that polygon on the google map
at the specified location.

Does anyone have some sample code for a polygon overlay? I went
through the MapView tutorial on the Android Dev site, and that was
great to get me started. But that uses a GeoPoint overlay... I guess
i am looking for more of a GeoPolygon (??) overlay, but i checked the
google api and there is no such class.

Any help or links to documentation to do this would be great. I am
guessing i need to great an android.graphics.drawable.shapes.shape to
create the polygon, and then add it to an OverlayItem from the google
maps API?? But i am very confused on how to do this.

Thanks!

Pete
TreKing
2010-01-13 18:19:14 UTC
Permalink
Create a class derived from Overlay and override onDraw() to do your custom
drawing.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking
Post by Peter
Hi,
I am new to Android Dev and to this group. I wanted to do some work
with the MapView. Mostly some basic stuff like zooming to an address,
and the programatically drawing a shape (polygon) based on user input
of coordinates. Then i want to overlay that polygon on the google map
at the specified location.
Does anyone have some sample code for a polygon overlay? I went
through the MapView tutorial on the Android Dev site, and that was
great to get me started. But that uses a GeoPoint overlay... I guess
i am looking for more of a GeoPolygon (??) overlay, but i checked the
google api and there is no such class.
Any help or links to documentation to do this would be great. I am
guessing i need to great an android.graphics.drawable.shapes.shape to
create the polygon, and then add it to an OverlayItem from the google
maps API?? But i am very confused on how to do this.
Thanks!
Pete
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
Peter
2010-01-13 20:42:44 UTC
Permalink
Thanks... Any chance you could show a sample of that. I am new to
this and not real familiar with the coding approach.
-Pete
Post by TreKing
Create a class derived from Overlay and override onDraw() to do your custom
drawing.
---------------------------------------------------------------------------­----------------------
TreKing - Chicago transit tracking app for Android-powered deviceshttp://sites.google.com/site/rezmobileapps/treking
Hi,
I am new to Android Dev and to this group.  I wanted to do some work
with the MapView.  Mostly some basic stuff like zooming to an address,
and the programatically drawing a shape (polygon) based on user input
of coordinates.  Then i want to overlay that polygon on the google map
at the specified location.
Does anyone have some sample code for a polygon overlay?  I went
through the MapView tutorial on the Android Dev site, and that was
great to get me started.  But that uses a GeoPoint overlay... I guess
i am looking for more of a GeoPolygon (??) overlay, but i checked the
google api and there is no such class.
Any help or links to documentation to do this would be great.  I am
guessing i need to great an android.graphics.drawable.shapes.shape to
create the polygon, and then add it to an OverlayItem from the google
maps API??  But i am very confused on how to do this.
Thanks!
Pete
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en- Hide quoted text -
- Show quoted text -
TreKing
2010-01-13 20:55:04 UTC
Permalink
Sample of what? Deriving from the class and overriding a method should be
pretty straightforward:

public class MyOverlay exntends Overlay
{
...

void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
{
// Logic to figure out where to draw
// Use canvas to draw
}
...
}

And at some point you add this to the mapview's overlays:
MyOverlay mo = new MyOverlay();
mapView.getOverlays().add(mo);

The draw call gets called for you when the map gets drawn.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking
Post by Peter
Thanks... Any chance you could show a sample of that. I am new to
this and not real familiar with the coding approach.
-Pete
Post by TreKing
Create a class derived from Overlay and override onDraw() to do your
custom
Post by TreKing
drawing.
---------------------------------------------------------------------------­----------------------
Post by TreKing
TreKing - Chicago transit tracking app for Android-powered deviceshttp://
sites.google.com/site/rezmobileapps/treking
Post by TreKing
Post by Peter
Hi,
I am new to Android Dev and to this group. I wanted to do some work
with the MapView. Mostly some basic stuff like zooming to an address,
and the programatically drawing a shape (polygon) based on user input
of coordinates. Then i want to overlay that polygon on the google map
at the specified location.
Does anyone have some sample code for a polygon overlay? I went
through the MapView tutorial on the Android Dev site, and that was
great to get me started. But that uses a GeoPoint overlay... I guess
i am looking for more of a GeoPolygon (??) overlay, but i checked the
google api and there is no such class.
Any help or links to documentation to do this would be great. I am
guessing i need to great an android.graphics.drawable.shapes.shape to
create the polygon, and then add it to an OverlayItem from the google
maps API?? But i am very confused on how to do this.
Thanks!
Pete
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en- Hide quoted
text -
Post by TreKing
- Show quoted text -
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
Loading...