I am using Google Map iOS sdk. I added polyline on my google map using the following code. But now I want add arrow at the end of this line. How to solve this issue?
GMSMutablePath *path = [GMSMutablePath path];
[path addLatitude:-37.81319 longitude:144.96298];
[path addLatitude:-31.95285 longitude:115.85734];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeWidth = 3.f;
polyline.map = mapaView;
You can use GMSMarker to indicate endpoint of your polyline:
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(22.200000, 114.1333900);
marker.title = #"Endpoint";
marker.map = mapView;
Related
Annotations are not shown on map.what could be the reason ? pls help.i cannot see any Pin or Annotations on the map,it is showing area near portugal,spain etc.
addressArray = dictionary[#"data"][#"centers"];
NSArray *latitude =[dictionary[#"data"][#"centers"]valueForKey:#"lat"];
NSArray *longitude=[dictionary[#"data"][#"centers"]valueForKey:#"lng"];
NSString *cname=[dictionary[#"data"][#"centers"]valueForKey:#"category_name"];
loaderView.hidden = true;
NSLog(#"%#",latitude);
NSLog(#"%#",longitude);
NSLog(#"%#",cname);
UIImage *pinImage = [UIImage imageNamed:#"map_gym"];
GMSMarker *mark=[[GMSMarker alloc]init];
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([[latitude objectAtIndex:0] doubleValue] ,[[longitude objectAtIndex:0] doubleValue]);
NSLog(#"%#",[latitude objectAtIndex:0]);
NSLog(#"%#",[longitude objectAtIndex:0]);
mark.position =coord;
mark.title=cname;
mark.icon=pinImage;
mark.infoWindowAnchor = CGPointMake(0.5, 0.25);
mark.groundAnchor = CGPointMake(0.5, 1.0);
mark.map=_mapView;
I think the coordinates of the marker is not properly implemented. Take a look at the code sample in Google's Document.
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(10, 10);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = #"Hello World";
marker.map = mapView_;
Try adjusting your code to this.
E.g.
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([[latitude objectAtIndex:0] doubleValue] ,[[longitude objectAtIndex:0] doubleValue]);
GMSMarker *marker = [GMSMarker markerWithPosition:coord];
marker.title = #"Hello World";
marker.map = mapView_;
Initialy created poly line and added some path to it . after creating this polyline i need add some other points based on gps location and drawing polyline again .is that redraw again the path.
_path = [GMSMutablePath path];
[_path addLatitude:12.9716 longitude:77.5946]; // bangalore
[_path addLatitude:13.3710 longitude:76.6413]; // Fiji
[_path addLatitude:15.3173 longitude:75.7139]; // Hawaii
[_path addLatitude:15.3647 longitude:75.1240]; // Mountain View
GMSMarker *marker1 = [[GMSMarker alloc] init];
marker1.position = CLLocationCoordinate2DMake(12.9716, 77.5946);
marker1.title = #"Bangalore";
marker1.groundAnchor = CGPointMake(0.2, 0.9);
marker1.appearAnimation = kGMSMarkerAnimationPop;
marker1.icon = [UIImage imageNamed:#"Flag Filled -50.png"];
marker1.snippet = #"India";
marker1.map = _mapView;
GMSMarker *marker2 = [[GMSMarker alloc] init];
marker2.position = CLLocationCoordinate2DMake(13.3710, 76.6413);
marker2.title = #"Tumkur";
marker2.groundAnchor = CGPointMake(0.3, 0.9);
marker2.snippet = #"India";
marker2.icon = [UIImage imageNamed:#"Flag Filled -50.png"];
marker2.map = _mapView;
GMSMarker *marker3 = [[GMSMarker alloc] init];
marker3.position = CLLocationCoordinate2DMake(15.3173, 75.7139);
marker3.title = #"Mysore";
marker3.groundAnchor = CGPointMake(0.3, 0.9);
marker3.snippet = #"India";
marker3.icon = [UIImage imageNamed:#"Flag Filled -50.png"];
marker3.map = _mapView;
GMSMarker *marker4 = [[GMSMarker alloc] init];
marker4.position = CLLocationCoordinate2DMake(15.3647, 75.1240);
marker4.title = #" Hubli";
marker4.groundAnchor = CGPointMake(0.3, 0.9);
marker4.snippet = #"India";
marker4.icon = [UIImage imageNamed:#"Flag Filled -50.png"];
marker4.map = _mapView;
marker4.rotation = 180;
CLLocationCoordinate2D circleCenter1 = CLLocationCoordinate2DMake(15.3647, 75.1240);
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:circleCenter1 zoom:10];
[_mapView animateWithCameraUpdate:updatedCamera];
_polyline = [GMSPolyline polylineWithPath:_path];
_polyline.strokeColor = [UIColor blueColor];
_polyline.strokeWidth = 1.f;
_polyline.map = _mapView;
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
static CLLocation *lastKnownLocation = nil;
if(lastKnownLocation == nil) lastKnownLocation = [locations lastObject];
else
{
CLLocation *currentLoc = [locations lastObject];
// Forming GMSPath from User's last location to User's current location.
GMSMutablePath *path = [GMSMutablePath new];
[path addCoordinate:[lastKnownLocation coordinate]];
[path addCoordinate:[currentLoc coordinate]];
GMSPolyline *polyLine = [GMSPolyline polylineWithPath:path];
polyLine.strokeColor = [UIColor redColor];
polyLine.strokeWidth = 2.f;
polyLine.map = googleMap;
// Saving current loc as last known loc,so that we can draw another GMSPolyline from last location to current location when you recieved another callback for this method.
lastKnownLocation = currentLoc;
}
}
Above code will draws path on google map when app got new location update(from second time onward).
Hope that helps,
Get back to me if you need some more deep info.
I tried this
GMSMarker *marker = [[GMSMarker alloc]init];
marker.icon = [UIImage imageNamed:#"pin2.png"];
marker.position = CLLocationCoordinate2DMake(lati, longi);
marker.groundAnchor = CGPointMake(0.5, 0.5);
marker.draggable = YES;
marker.map = mapView;
but I did not get the image.
I think you are missing this line:
[mapView setSelectedMarker:marker];
I want use fitBounds method in GoogleMaps for ios SDK and view does not fit. My varaibles are all right (path, arrays, etc...) because I can see polyline with markers on map. The only thing that does not work is fit to view. Where I have made mistake? thank you.
// Create a 'normal' polyline.
GMSPolyline *polyline = [[GMSPolyline alloc] init];
GMSMutablePath *path = [GMSMutablePath path];
locationInfoArray = [LocationInfoMemoryManager loadLocationDataWithPath:_locationInfoPathString];
for (int i=0; i<locationInfoArray.count; i++) {
LocationInfo* locationInfo = locationInfoArray[i];
CLLocationCoordinate2D locationPoint = {locationInfo.latitude, locationInfo.longitude};
[path addCoordinate:locationPoint];
}
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[locationInfoArray[0] latitude]
longitude:[locationInfoArray[0] longitude]
zoom:5 ];
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
polyline.path = path;
polyline.strokeColor = [UIColor blueColor];
polyline.strokeWidth = 10.f;
polyline.zIndex = 15; // above the larger geodesic line
polyline.map = mapView;
GMSMarker *startMarker = [[GMSMarker alloc] init];
startMarker.title = #"Start";
startMarker.snippet = #"Info will be here";
startMarker.position = CLLocationCoordinate2DMake([[locationInfoArray firstObject] latitude], [[locationInfoArray firstObject] longitude]);
startMarker.map = mapView;
startMarker.flat = NO;
//sydneyMarker.rotation = 30.0;
mapView.selectedMarker = startMarker;
GMSMarker *finishMarker = [[GMSMarker alloc] init];
finishMarker.title = #"Finish";
finishMarker.snippet = #"Info will be here";
finishMarker.position = CLLocationCoordinate2DMake([[locationInfoArray lastObject] latitude], [[locationInfoArray lastObject] longitude]);
finishMarker.map = mapView;
finishMarker.flat = NO;
mapView.selectedMarker = finishMarker;
//Here is probably problem
GMSCoordinateBounds *bounds; = [[GMSCoordinateBounds alloc] initWithPath:path];
GMSCameraUpdate *update = [GMSCameraUpdate fitBounds:bounds withPadding:20];
[mapView moveCamera:update];
self.view = mapView;
Is this code in loadView or viewDidLoad? Based on these earlier questions, I think camera updates only work correctly from viewWillAppear:
GMSCameraUpdate zooming out to the max distance rather than around a path
Fit bounds not working as expected
I'm working on an app for iOS and i'm running into some trouble with the google maps sdk.
My app gets a list of coordinates and draws a polyline between them as well as start and finish markers. At the moment, this all occurs successfully. What i'm trying to do now is update the camera to contain the entire path. Here is my code currently:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[[sharedModel startNode] nodeLocation].latitude
longitude:[[sharedModel startNode] nodeLocation].longitude
zoom:18];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
GMSMutablePath *path = [GMSMutablePath path];
for (int i = 0; i < [results count]; i++)
{
[path addCoordinate:[[results objectAtIndex:i] nodeLocation]];
}
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeWidth = 10;
polyline.map = mapView_;
GMSMarker *marker1 = [[GMSMarker alloc] init];
marker1 = [GMSMarker markerWithPosition:[[results objectAtIndex:0] nodeLocation]];//[[sharedModel startNode] nodeLocation]];
marker1.title = #"Start";
marker1.map = mapView_;
GMSMarker *marker2 = [[GMSMarker alloc] init];
marker2 = [GMSMarker markerWithPosition:[[results lastObject] nodeLocation]];
marker2.title = #"Finish";
marker2.map = mapView_;
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithPath:path];
GMSCameraUpdate *update = [GMSCameraUpdate fitBounds:bounds];
[mapView_ moveCamera:update];
self.view = mapView_;
When I run this, my markers and polyline all show up in the right locations but the map is zoomed out to the max distance it can go (although it is centered over the path). Any advice?
Is this code in loadView? Try maybe creating the map view in loadView, but updating the camera later, maybe in viewDidLoad or viewWillAppear.
Based on the answer to this question I'm thinking that maybe the camera update methods don't work properly from loadView:
Fit bounds not working as expected