設置的GMSMapView
和GMSCameraPosition
-(void)setup {
GMSCameraPosition *camera =
[GMSCameraPosition cameraWithLatitude:71.00
longitude:45.124
zoom:14
bearing:0
viewingAngle:0];
self.mapView = [GMSMapView mapWithFrame:CGRectMake() camera:camera];
self.mapView.delegate = self;
self.mapView.mapType = kGMSTypeNormal;
//current location on map
self.mapView.myLocationEnabled = YES;
//map controls
self.mapView.settings.compassButton = YES;
self.mapView.settings.myLocationButton = YES;
//constraining the zoom options
[self.mapView setMinZoom:10 maxZoom:18];
[self.view addSubview:self.mapView];
}
調用此方法用於在地圖上ploting multiple pins
。
-(void)plotMutliplePinsOnMap:(NSArray *)mapArray
{
for(int i=0;i<[mapArray count];i++)
{
double_lat = [[[mapArray objectAtIndex:i]valueForKey:@"latitude"] doubleValue];
double_long = [[[mapArray objectAtIndex:i]valueForKey:@"longitude"] doubleValue];
GMSMarker *mkr = [[GMSMarker alloc] init];
mkr.icon = [UIImage imageNamed:@"map_black"];
if (double_lat !=0 && double_long!=0)
{
[mkr setPosition:CLLocationCoordinate2DMake(double_lat, double_long)];
[mkr setTitle:[[mapArray objectAtIndex:i] valueForKey:@"placeName"]];
[mkr setSnippet:[[mapArray objectAtIndex:i] valueForKey:@"address"]];
[mkr setMap:self.mapView];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:double_lat longitude:double_long zoom:5];
self.mapView.camera=camera;
}
}
}
https://stackoverflow.com/questions/16191436/adding-multiple-pins-on-google-map-in-ios – Pipiks
檢查URL https://stackoverflow.com/questions/27163318/how- mkmapview -ios –
下面的行是必須的[mkr setTitle: