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)
Related
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 am working on an app where i need to load hebrew map and also update map as location change and draw path from initial location to change location.
I have worked on apple map and google map. But i find some difficulty in loading israel country map on it. Is it possible to load such map on iOS? Any suggestions are most welcome!
To load hebrew map
Based from this SO question, Google Maps iOS SDK uses the system region/language settings but doesn't expose any way to manually force any particular language. Geocoding responses (using the SDK classes) and the map labels both reflect these device settings, thankfully.
Draw path from initial location to change location
You can use Polylines to draw lines on the map. A GMSPolyline object represents an ordered sequence of locations, displayed as a series of line segments. You can set the color of a polyline with GMSStrokeStyle.
To create a polyline, you'll need to specify its path by creating a corresponding GMSMutablePath object with two or more points. Each CLLocationCoordinate2D represents a point on the Earth's surface. Line segments are drawn between points according to the order in which you add them to the path. You can add points to the path with the addCoordinate: or addLatitude:longitude: methods.
Example:
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(-33.85, 151.20)];
[path addCoordinate:CLLocationCoordinate2DMake(-33.70, 151.40)];
[path addCoordinate:CLLocationCoordinate2DMake(-33.73, 151.41)];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
You can check this related SO thread.
Loading israel country map
Check these links:
How to get country specific result with Google autocomplete place api ios sdk?
Is there a way to display a single country in Google map? It should be only one country, not parts from other countries included
Hope this helps!
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.
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.
As we have seen there is a circle around current location in iOS mkmapview. Is there any way to draw a similar circle in mkmapview for location other then current location?
If you look at the documentations for MKCircle: http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKCircle_class/Reference/Reference.html and MKCircleView: http://developer.apple.com/library/iOS/documentation/MapKit/Reference/MKCircleView_class/Reference/Reference.html both of which are part of the MapKit API,
you'll find tools for drawing circles!
As mentioned at this link Circle around a point on an MKMapView
there are no easy way to create animations for these circles, however the advantage is that they will provide you with a degree of accuracy for your coordinates on your map!
The steps to creating the circles, one way, is here: Drawing a circle on mapkit
Basically, create an MKCircle object using circleWithCenterCoordinate:radius: method and add it to your mapView (using addOverlay: method)
Next, in the mapView delegate, implement mapView:viewForOverlay: method, create and setup MKCircleView instance there and return it.