Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a shape on the map fragment by touching it using google map V2

Hello everyone,

I am using Google map V2 and I have to draw a shape on the map fragment by touching it. i.e if I rotate my fingers on the map a shape should be generated. I am getting problem because Google mapV2 does not provide lat ,long when we touch the map. I have no need to click on MapV2 so click listener is not useful for me.

So please share any idea or code to get the latitude and longitude from the map by touching it. So that I would draw a shape by touching the map.

like image 401
Agnihotri. Avatar asked May 23 '13 11:05

Agnihotri.


1 Answers

GoogleMap doesn't have a touch listener, so you'll have to override onTouchEvent for the parent view of your MapFragment. Once you have the screen coordinates of your touch event, you can get the Lat/Long by using Projection (Doc here). Simply do

LatLng coords = mapFragment.getMap().getProjection().fromScreenLocation(point);

Where point is a Point describing the location of your touch event.

Once you have the LatLng describing your touch event, you can draw shapes using either Circle or Polygon. Google's tutorial on drawing shapes will do a better job of explaining it than I could: Shapes - Google Maps v2

Hope this helps!

like image 95
crocboy Avatar answered Oct 11 '22 14:10

crocboy