Wednesday, January 12, 2011

Create a Radius Around a Point in Google Map

Question : How do I create a 9000 meters buffer radius from a point and display placemarks that intersect that buffer.
Answer : Google Map API for android has a class that reads and draw your current location in the map.
That class is "MyLocationOverlay". The class has a "draw" method that will be called everytime user pan or zoom on the map.
So to draw a circle radius of your current location, we need to extends this class and override its draw method.

Then, we create our view, one map view, one textbox and one button


After that, we need to create our main class. TukangAndroidApp.java

Dont forget to edit AndroidManifest.xml to add permissions and google map library


Run your application.
Tips : Set the GPS location from the DDMS first before you press Search, otherwise you will encounter NullPointerException
If all goes well, your application will be like this

Notice in TukangAndroidApp.java, our displayResult method didnt do anything, so we will implement the method to return some placemarks that intersect our buffer.
First, we should extends ItemizedOverlay class to create our placemark


Next, we will implement the displayResult method.
Our last TukangAndroidApp.java should look like this

Run the application, and you can see that our application will work well.







Have fun!

16 comments:

  1. Perfect........I was looking for hours this code....

    ReplyDelete
  2. How can i get the current location

    ReplyDelete
  3. Why does this application crashes after some time?

    ReplyDelete
  4. @CEC@IT open DDMS view, click Emulator Control button (nearly top of the screen), after that you will see Location Controls.

    ReplyDelete
  5. can some one plz upload the zip file as i cant get the code working

    ReplyDelete
  6. That was awesome
    I follow your step but when I try to implement the displayResult method , It's has stopped.

    ReplyDelete
  7. Awesome! Just what I was looking for..tiny question..I need to show a list of locations surrounded by the circle definigng the radius.
    What can I do to make sure I add the markers and draw the circle at the same time?

    ReplyDelete
  8. why does the circle disappear when I zoom passed a certain zoom level?

    ReplyDelete
  9. Great work.. thanks a lot.... This article did many things to me...

    ReplyDelete
  10. Can you give me a full project of this application ?
    I don't get it how these things work.

    ReplyDelete
  11. Can you help soving this problem http://stackoverflow.com/questions/33035373/show-markers-near-the-device-in-android/33037739#33037739 ?

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Hi, is it possible to maybe provide us with a source code, more like a Github link if you do not mind..

    ReplyDelete