如何在我的iOS应用程序中为Google地图创build多个标记?
我无法find我如何在iOS应用程序的谷歌地图上放置多个标记的答案。 我知道这可以做,但我不知道该怎么做。 这是使用一些谷歌文档,但我的应用程序将显示纽约市的地点。 这是我错误的代码:在GoogleMapsViewController.m我有以下代码:
// GoogleMapsViewController.m // GoogleMaps1 // // Created by Meghan on 2/1/14. // Copyright (c) 2014 Meghan. All rights reserved. // #import "GoogleMapsViewController.h" #import <GoogleMaps/GoogleMaps.h> @interface GoogleMapsViewController () @end @implementation GoogleMapsViewController { GMSMapView *mapView_; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. { // Create a GMSCameraPosition that tells the map to display the // coordinate -33.86,151.20 at zoom level 6. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:6]; mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView_.myLocationEnabled = YES; self.view = mapView_; // Creates a marker in the center of the map (center for Sydney). NSMutableArray *markersArray = [[NSMutableArray alloc] init]; for(int i=0;i<2;i++) { id sydney = [markersArray objectAtIndex:0]; GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); marker.title = @"Sydney"; marker.snippet = @"Australia"; marker.map = mapView_; id newcastle = [markersArray objectAtIndex:1]; GMSMarker *marker1 = [[GMSMarker alloc] init]; marker1.position = CLLocationCoordinate2DMake(-32.92, 151.78); marker1.title = @"Newcastle"; marker1.snippet = @"Australia"; marker1.map = mapView_; } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
我find了一个方法来使它工作。 我只是以相同的格式添加位置。 这是我的代码:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. { // Create a GMSCameraPosition that tells the map to display the // coordinate -33.86,151.20 at zoom level 6. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:6]; mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView_.myLocationEnabled = YES; self.view = mapView_; // Creates a marker in the center of the map. GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); marker.title = @"Sydney"; marker.snippet = @"Australia"; marker.map = mapView_; GMSMarker *marker1 = [[GMSMarker alloc] init]; marker1.position = CLLocationCoordinate2DMake(-32.92, 151.78); marker1.title = @"Newcastle"; marker1.snippet = @"Australia"; marker1.map = mapView_; } }
尝试一下
- (void)viewDidLoad { [super viewDidLoad]; Lat=[NSArray arrayWithObjects:@"22.5851",@"22.5830002",@"22.5831",@"22.3932",@"22.3409", nil]; Long=[NSArray arrayWithObjects:@"88.3468",@"88.33729089999997",@"88.2833",@"87.7427",@"87.3258", nil]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:22.5851 longitude:88.3468 zoom:6]; GMSMapView *mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView_.myLocationEnabled = YES; self.view = mapView_; for (int i=0; i<[Lat count]; i++) { GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake([[Lat objectAtIndex:i]doubleValue], [[Long objectAtIndex:i]doubleValue]); marker.title = @"Any Titel"; marker.snippet = @"India"; marker.map = mapView_; } }
- 如何在GMSMapView中显示一个圆
- 限制Google AutoComplete API只显示附近的位置
- 使用地图应用程序iOS生成步行路线
- 谷歌地图iOS sdk获取挖掘重叠坐标
- 错误使用未parsing的标识符GMSPlacePickerConfig&GooglePlacePicker? (Google Places 2.0)
- 围绕Google地图标记iOS的脉冲环animation
- Google Maps iOS SDK和故事板
- 获取当前位置iOS,Google Maps API的坐标
- 更新到IOS11和Xcode9后的问题! “com.google.Maps.LabelingBehavior”,“TIC Read Status”