Google Map Kit, draw polylines for walk like google map ios - ios

I wants to draw polyline for walk like google map app in ios using google maps ios sdk. For more clear understanding i am uploading image that is from google map app(ios.)

Are you asking how to achieve the dotted polyline effect? If so, I don't believe that is supported in the SDK.
You can manually create a similar effect with GMSCircles.
for(int x = 0; x < [self.path count]; x++)
{
CLLocationCoordinate2D coord = [self.path coordinateAtIndex:x];
//draw circle coord
GMSCircle *circle = [GMSCircle circleWithPosition:coord radius:20];
circle.fillColor = [UIColor blueColor];
circle.strokeColor = [UIColor blackColor];
circle.strokeWidth = 2;
circle.map = mapView;
}
For this to really look like the original example you will probably need to add additional points onto the line in order for the circles to be evenly spaced out. For that you could do something like this.
for(all the points in the path)
{
if(the distance from pointA to pointB is > some distance)
{
centerPtr = center point of pointA and pointB
insert centerPt in path
}
}
You can turn this into a simple recursive function that should give you something similar to what you are looking for.

Related

Remove travelled GMSPolyline segment

I am using google map sdk for ios to provide directions between current user location and an end location. I have so far achieved to draw a GMSPolyline between the current user location and the end location using the code below and it's working great.
GMSPath *encodedPath = [GMSPath pathFromEncodedPath:encodedPathSting];
self.polyline = [GMSPolyline polylineWithPath:encodedPath];
self.polyline.strokeWidth = 4;
self.polyline.strokeColor = [UIColor colorWithRed:55.0/255.0 green:160.0/255.0 blue:250.0/255.0 alpha:1.0];;
self.polyline.map = self.mapView;
Is it possible to remove a part of the GMSPolyline that has been covered by the user through driving/walking? The GMSPolyline must gradually decrease in length as we trace the path.
One way to achieve this is by redrawing the path repeatedly but this is not or may not be efficient.
Thanks.
So get the latlng point of the polyline in an array as described here:
//route is the MKRoute in this example
//but the polyline can be any MKPolyline
NSUInteger pointCount = route.polyline.pointCount;
//allocate a C array to hold this many points/coordinates...
CLLocationCoordinate2D * routeCoordinates = malloc(pointCount * sizeof(CLLocationCoordinate2D));
//get the coordinates (all of them)...
[route.polyline getCoordinates: routeCoordinates
range: NSMakeRange(0, pointCount)
];
//this part just shows how to use the results...
NSLog(#"route pointCount = %d", pointCount);
for (int c = 0; c < pointCount; c++) {
NSLog(#"routeCoordinates[%d] = %f, %f",
c, routeCoordinates[c].latitude, routeCoordinates[c].longitude);
}
//free the memory used by the C array when done with it...
free(routeCoordinates);
Then, implement a while loop for the first point as you move along the path like this:
int c = 0;
while (pointCount.size() > 0)
{
pointCount.get(0).remove();
}
Note: I'm not that experienced with iOS and haven't tested this solution. Treat it as a suggestion rather than a fix. Thanks!
Hope it helps!

Google Maps draws a wrong circle, if it's borders reach the south pole

I'm trying to draw a circle with given radius and center point. However, for some reasons Google Maps for iOS reverts the result, if the circle reaches south pole.
Here is the result with radius = 6000 km and center in Sydney. It looks just fine:
But if I set the radius as 7000 km, the result becomes useless:
Expected result is:
Code I use for adding the circle is pretty basic:
GMSCircle *geoFenceCircle = [[GMSCircle alloc] init];
geoFenceCircle.radius = 6000000; // Meters
geoFenceCircle.position = _sydneyMarker.position;
geoFenceCircle.fillColor = [UIColor colorWithWhite:0.7 alpha:0.5];
geoFenceCircle.strokeWidth = 3;
geoFenceCircle.strokeColor = [UIColor orangeColor];
geoFenceCircle.map = mapView;
Is there any way to fix this?

Manually drawing a circle with a radial distance from center lat/lng using google maps ios sdk

I need to send lat/lng coordinates to a 3rd party API and it doesn't look like it's possible to extract lat/lng coordinates from a GMSCircle, so
I was thinking about generating an array of CGPoints and using GMSProjection to extract the location coordinates, however the radius needs to be exactly 1.5 miles; so with regard to the zoom level would I need to resort to something like this: https://gis.stackexchange.com/questions/7430/what-ratio-scales-do-google-maps-zoom-levels-correspond-to to calculate it?
Is there a better way to go about this? I feel like this would be a pretty common use case
Figured it out, I ended up using the GMSGeometryUtils GMSGeometryOffset function to get the offset from my origin and make a circle.
NSMutableArray *path = [NSMutableArray array];
for (int i = 0; i < 60; i++) {
CLLocationCoordinate2D locationCoordinate = GMSGeometryOffset(location.coordinate, 2414.02, i*6);
[path addObject:[[CLLocation alloc] initWithLatitude:locationCoordinate.latitude longitude:locationCoordinate.longitude]];
}

Outline of polyline in Google Maps sdk for iOS

The requirement that I have is to have a green polyline to be showed on the map. But when the map is switched to satellite view, the green polyline becomes unclear.
I can't get the color of the polyline changed. So to distinguish the polyline from the background(Satellite view of the map), I need to draw white outline to the polyline.
I went through the documentation of GMSPolyline class and could not find anything using which I can outline the polyline with very thin two white lines.
Can anyone please give me suggestions as to how can I achieve this? (Without drawing/overlapping the main polyline with two boundary polylines)
The easiest way I've found is to draw a fatter line underneath your main polyline, thereby adding a stroke to either side.
When you define your main polyline(s), add a zIndex:
polyline.strokeColor = [UIColor whiteColor];
polyline.strokeWidth = 2;
polyline.zIndex = 10;
polyline.map = mapView;
Then add another polyline with the same path, modifying your original's strokeWidth and zIndex:
GMSPolyline *stroke = [GMSPolyline polylineWithPath:samePathAsYourMainPolyline];
stroke.strokeColor = [UIColor blackColor];
stroke.strokeWidth = polyline.strokeWidth + 1;
stroke.zIndex = polyline.zIndex - 1;
stroke.map = mapView;

Overlaying multiple polygons on the mapView-iOS

As you seen in the image, there are numbers of polygon on the top of the mapView. Each polygon overlays on the top of other polygon. This causes opacity problem and that misleads user to interpret colors by referring to colormap.
Before placing any polygons, first I want to remove/clear the new polygon area then add the polygon.
I hope my question clear! if not, please let me know. Appreciated in advance.
I have also add portion of my code below as a reference! Polygon data comes from server in JSON format and I get coordinates out of this data and add them as a polygon for each time stamp.
for(bb = 0; bb < [polygonArray count]; bb++){
coords = malloc(sizeof(CLLocationCoordinate2D) * [[polygonArray objectAtIndex:bb] count]);
for (int a = 0;a < [[polygonArray objectAtIndex:bb] count]; a++){
coords[a].latitude = [[[[polygonArray objectAtIndex:bb]objectAtIndex:a]objectAtIndex:0]doubleValue];
coords[a].longitude = [[[[polygonArray objectAtIndex:bb]objectAtIndex:a]objectAtIndex:1]doubleValue];
}
polygon = [[MKPolygon alloc]init];
polygon = [MKPolygon polygonWithCoordinates:coords count:[[polygonArray objectAtIndex:bb]count]];
[previousPolygons addObject:polygon];
[mapView addOverlay:polygon];
}
}
Hmm. I'm a little unclear on what you want to do. If you simply want to remove a polygon, you'd have to some how find the polygon you want remove and run
[mapView removeOverlay:polygon]
If you want to remove all polygons then you could run
[mapView removeOverlays:mapView.overlays]

Resources