I am using google map for my ios app, what i want to achieve is like when user touches the map and drags the finger, then identify the coordinates and draw the line on the map and then want to get all the marker inside that polyline(circular). So for that i had to disable the movement of the map which i did as below:
_googleMapView.settings.scrollGestures = NO;
_googleMapView.settings.zoomGestures = NO;
But then now i want to draw a line for which i got this link as below:
Free hand drawing in google maps-iOS
This link says that i have to do as follows:
To draw a line use polyline. Refer to Google Maps Shapes.
To use polyline you need to give locatoin coordinates. To convert a point on screen to coordinate use coordinateForPoint:(CGPoint)point method of GMSProjection class.
But my problem is i want to get the CGPloint of array when user drags and the map(which inturn will make a polyline), but i am really unaware of how will i get the CGPoints.
https://github.com/saru2020/SARMapDrawView
This project did exactly what i wanted, helpful link.
Related
I'd like to allow users to mark some area on map. This area should be any closed shape. For instance user can draw something like this:
In next step I'd like to calculate region of this shape. How can I achive this?
You can use MKPolygon.
First of all you'll need to disable user interaction on the map view so that it won't move around while you're trying to draw on it. Next up you can use the UIResponder functions touchesBegan, touchesMoved and touchesEnded. As you move through these three functions you can record the points the user has pressed. Lastly you can then create an MKPolygon from this array of points that you have recorded.
I am trying to enhance Google Maps bit deeper. I want to draw a curb line or you can say square on GMSMapview.
How ever I have tried to draw a lines using GMSPolygon. Lines are drawn as well but also want to get touch event when anyone wants to touch curb line I should get some event.
I am not sure at this moment that Google Maps will fulfil my requirements or not.
P.S : I have used google maps already in my app and now want to draw curb line(square) and should be notified when user tap on it and I should also have facility to clear that curb line from map.
You can user the delegate method mapView:didTapAtCoordinate to get the coordinate and then use the method GMSGeometryIsLocationOnPath or GMSGeometryIsLocationOnPathTolerance in the GMSGeometryUtils module
As an alternative, as long GMSPolygon is an GMSOverlay, you can use the delegate method mapView:didTapOverlay: to check if the coordinate lies on the path
I have a requirement that in some cases a GMSPolyline be moved from one location to another. Here is the scenario:
A user opens a GMSMapView and creates a GMSPolyline feature.
Then the user changes the map position
The user taps a button to center the newly created polyline in the new view position, that is, the newly created line feature is moved to the center of the new camera view.
So far I can find no resources for how to do this. There are plenty of examples for creating and editing GMSPolyline features, but not finding one for moving the entire feature. Can anyone point me to an example for doing this?
Thanks!
You have to change the coordinates of all the locations that make the GSMPath that is the base of your GMSPolyline. For each location you can calculate the new point using GMSGeometryOffset, then you draw a new polyline.
Or you can use -(instancetype) pathOffsetByLatitude:longitude: of GMSPath on the GMSPath that describes your polyline.
You use one or the other according the data that you have available (as an example the start and end target of the GMSCameraPosition after a pan)
I'm fairly new to ios and I would like to know what would be the best approach to draw polyline on google map while user is on the move. So it would only show the path the user has traveled. I'm thinking about using current location as the destination and redraw the polyline as user moves.
EDIT : I'm not even sure if google map is the way to go for this particular scenario since this app is free and there will be fee for API call over 2500 times/day. Is it better to go with Apple Map?
Following these guidelines:
You need to create a GMSMutablePath and add the current user location. As the user moves you add more coordinates to the GMSMutablePath.
When you need to draw the line just instantiate a new GMSPolyline object and set the map property of the GMSPolyline removing the previously drawn polyline setting it's map property to nil.
I want to implement a functionality in which any one can draw any shape on the Google Maps via fingers. Then I want to show the markers or pins on the map which only lies in that area/Shape.
I know that there are various ways to draw a shape on google Map but how can i know that any particular pin lies inside that area drawn by the user/person. Is there any Google API available for it. Thanks in advance.
You could try storing the shape as UIBezierPath. Loop through your list of locations and translate long and lat to CGPoint so you can call
BOOL showLocation = [bezierPath containsPoint:point];