Drawing polyline in realtime - ios

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.

Related

Move a GMSPolyline in iOS

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)

Get array of CGPoint while user wants to draw a line

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.

Drawing Polyline on an ios Mapview

In my Xamarin ios app I have to draw the path as user walks,
I am planning to do this by drawing Polyline to a Map view by fetching Lattitude & Longitude from CClocationManager, But I have to deal with N number of Lattitude & Longitude in this case,
Is there any simple approach to do this? In our scenario We won't be knowing the destination , User will Just start a run from a point and we have to track his path on map by drawing a line, How could I do this?
A possible solution could be to save the current last known position, which also represents you endpoint of a polyline. On a location change use it as a starting point for the next polyline. That way you draw the route with multiple polylines piece by piece.

Draw path in MKMapView using Google Map

I implement MKMapView in my application to draw a path between two place,i found all lat long between two point using google map API but it shows the path through road.
My problem is that i want to show the path in building,
For example:
I want to draw path between the gate1 to gate 2 of Building, i pass the "to and from" lat-long in to the google MAP API, it shows the path through road so it shows the wrong distance.
I tried the indoor map also but it works only in register buildings.

How to remove GMSPolygon from GMSMapView

Does exist any way to remove GMSPolygons from GMSMapView?
It does not seem to exist a property of GMSMapView containing them (as GMSPlolyLines), should I clear the map and render all again?
thanks
When you create the GMSPolygon you set its map property to add it to the map. To remove it from the map, set its map property to nil. This means you need to keep your own record of the polygons which you've added to the map, which you want to be able to remove later.
For example mySavedPolygon.map = nil
From google maps document
clear Clears all markup that has been added to the map, including markers, polylines and ground overlays.
So you just use
[mapView clear];
This should clear the polygons.
This has been updated, has I am using the clear function, and was looking for a way to keep the polygons while using this.
I've just confirmed against the Google Maps API Reference.
Clears all markup that has been added to the map, including markers, polylines and ground overlays.
https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_map_view.html#a28e6b8aeb7c8dc9025dc001f2a5d2c9b

Resources