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_;
Related
for (int i=0; i<self.busRoutesArr.count-1; i++)
{
NSString *lat = [self.latArr objectAtIndex:i];
NSString *lon = [self.longArr objectAtIndex:i] ;
double lt=[lat doubleValue];
double ln=[lon doubleValue];
NSLog(#"%f, %f",lt,ln);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:lt
longitude:ln
zoom:60];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectMake(10, 100, 250, 250) camera:camera];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = camera.target;
marker.snippet = #"Hello World";
marker.map = mapView;
mapView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:mapView];
}
Only 1 marker being displayed. I want to display all the markers and a line connecting them
The following code is for displaying all markers in the map.
for(int i=0;i<[array count];i++) {
GMSMarker *marker = [[GMSMarker alloc] init];
marker.animated=YES;
marker.position = CLLocationCoordinate2DMake(latitude,longitude);
marker.title = #"name";
marker.snippet = #"snippet";
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'm using google maps sdks to display locations on IOS app that i'm working on. Displaying single location works fine, but when i try to display multiple locations on a single map it gives a white screen. I have a restaurantsData object that consists of information pertaining to an array of restaurants (along with latitude and longitude for each). Now when try below code it gives a white screen. This is my first time using Google maps for IOS, please help me out.
Restaurant *res = [[Restaurant alloc] init];
for (res in _restaurantData) {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: [res.objectLocation.lat doubleValue]
longitude: [res.objectLocation.lng doubleValue] zoom: 5];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
GMSMarker *marker = [ [GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake([res.objectLocation.lat doubleValue], [res.objectLocation.lng doubleValue]);
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.icon = [UIImage imageNamed:#"fork_filled"];
marker.map = mapView;
}
Your loop must be like
for (Restaurant *res in _restaurantData) {
GMSMarker *marker = [ [GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake([res.objectLocation.lat doubleValue], [res.objectLocation.lng doubleValue]);
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.icon = [UIImage imageNamed:#"fork_filled"];
marker.map = mapView;
}
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 to add multiple pins on a google map, while it is being loaded.
I have a list of Latitude and Longitude values of nearby locations.
How can I show all these locations on the map with a pin. I am using Google SDK for iOS.
I am using the following code, but it didn't work for me.
NSMutableArray *array = [NSMutableArray arrayWithObjects:#"12.981902,80.266333",#"12.982902,80.266363", nil];
CLLocationCoordinate2D pointsToUse[5];
for (int i = 0; i < [array Size]; i++)
{
pointsToUse[i] = CLLocationCoordinate2DMake([[[[array objectAtIndex:0] componentsSeparatedByString:#","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:0] componentsSeparatedByString:#","] objectAtIndex:1] floatValue]);
[array removeObjectAtIndex:0];
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = pointsToUse[i];
[mapView_ animateToLocation:pointsToUse[i]];
[mapView_ addMarkerWithOptions:options];
}
I have tried enough to search for it but there isn't enough documentation to answer my question.
Thanks in advance for the help.
This works for me:
for(GMSMarker*marker in array)
{
GMSMarker *mkr= [[GMSMarker alloc]init];
[mkr setPosition:CLLocationCoordinate2DMake(<coord>)];
[mkr setAnimated:YES];
[mkr setTitle:<Title>];
[mkr setSnippet:<Snippet>];
[mkr setMap:mapView_];
}
Using latest Google Maps SDK.
Hope it helps
self.view = mapView_;
for(int i=0;i<[array count];i++)
{
GMSMarker *marker = [[GMSMarker alloc] init];
marker.animated=YES;
marker.position = CLLocationCoordinate2DMake(latitude,longitude);
marker.title = #"name";
marker.snippet = #"snippet";
marker.map = mapView_;
}
This worked for me!
For swift we can use
for i in 0..<array.count() {
var marker = GMSMarker()
marker.animated = true
marker.position = CLLocationCoordinate2DMake(latitude, longitude)
marker.title = "name"
marker.snippet = "snippet"
marker.map = mapView_
}