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;
Related
I want to show completely GMSCircle on MapView but radius of circle is dynamically changed.
When radius is changed then MapView will be automatically adjust to view the complete circle on map to show all marker.
In Swift language, I have found a solution which may be helpful for me as given here: Change Camera Zoom based on Radius Google Maps iOS SDK
But I have to implement this in Objective-c and in Objective-c we didn't have bound property for GMSCircle.
Thanks in Advance,Please guide me.
you have to set zoom level according to your radius
// SET ZOOM LEVEL
int zoomLevel = 11;
double radius = raduismeter+ raduismeter / 2;
double scale = radius / 500;
zoomLevel = (int) (16 - log(scale) / log(2));
zoomLevel++;
you have to set and calculate zoom level according to your need. Than you have to set radius circle
GMSCircle *geoFenceCircle = [[GMSCircle alloc] init];
geoFenceCircle.position =PinDropCoordinates;
geoFenceCircle.strokeWidth = 0.5;
geoFenceCircle.strokeColor = [UIColor redColor];
NSLog(#"%#",geoFenceCircle);
geoFenceCircle.radius =5000.00;
geoFenceCircle.map = self.mapView;
After setting circle you have to animate your Camera accordingly.
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:3] forKey:kCATransactionAnimationDuration];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:PinDropCoordinates.latitude
longitude:PinDropCoordinates.longitude zoom:zoomLevel];
[self.mapView animateToCameraPosition: camera];
[CATransaction commit];
I'm able to draw GMSPolyline on GoogleMaps with array of locations like this
GMSMutablePath *path = [GMSMutablePath path];
for (int i = 0; i <anotherArray.count; i++) {
NSString *string1 = [anotherArray2 objectAtIndex:i];
NSString *string2 = [anotherArray objectAtIndex:i];
[path addCoordinate:CLLocationCoordinate2DMake(string1.doubleValue,string2.doubleValue)];
}
GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];
rectangle.strokeColor = [UIColor blueColor];
rectangle.map = mapView_;
rectangle.strokeWidth = 2.0f;
But the locations I'm getting from backend server.
So I have to refresh every 10 seconds,getting new locations and adding it to existing path. These are all working fine.
But when I am adding new locations to existing path is moving very fast.
Cause I have a GMSMarker at starting of path and it is looking like jumping from one place to another place.
So how can I animate GMSMarker like slowly moving from one place to another place?
Check on this tutorial. It states how to draw the route lines on the map using the GMSPolyline class. From this related SO thread:
Change your else block to be something more like this:
[CATransaction begin];
[CATransaction setAnimationDuration:2.0];
marker.position = coordindates;
[CATransaction commit];
We enable you to use Core
Animation
for animating Google Maps.
For a worked sample, please see
AnimatedCurrentLocationViewController.{c,m} in the SDK sample
application.
Also based from this SO post, avoid using 1px stroke-width of line. Instead, use 4px stroke-width. You can also check on this GitHub sample.
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?
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.
I am making the navigation application by drawing a direction between 2 points. I successfully archive the functionality.
But the direction line is drawn on top of the road label and that label cannot be read as show in the picture below.
this is my code to draw overlay
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
MKPolylineView *overlayView = [[MKPolylineView alloc] initWithPolyline:overlay];
overlayView.lineWidth = 10.0f;
//overlayView.strokeColor = [[UIColor redColor] colorWithAlphaComponent:0.5f];
overlayView.strokeColor = [UIColor redColor];
return overlayView;
}
I can overcome this with a transparent line but it is not the efficient way.
The best way is to draw the line between the map layer and label layer of MKMapView but i don't know how can i archive that.
So any help please.
Thanks.
Assuming you are writing this for iOS maps (not google maps as you tagged the question) and using iOS 7 then when you add the overlay to the map view you have the option of defining which level it is on addOverlay:level:. The levels are defined in the MKMapView class reference
[theMapView addOverlay:theOverlay level:MKOverlayLevelAboveRoads];