ios - 为 iOS 实现 Google map

标签 ios iphone google-maps dictionary

我已经给出了苹果 map 的替代方案,称为谷歌地图。此问答提供了如何创建谷歌地图并在 map 上创建带有描述的标记的解决方案。

最佳答案

  1. 首先完成此链接 https://developers.google.com/maps/documentation/ios/start 中列出的步骤

  2. 创建 map 的代码。

    CLLocationCoordinate2D coordinate = [self getLocation];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude
                                                longitude:coordinate.longitude 
                                                             zoom:15];
    mapView = [GMSMapView mapWithFrame:CGRectMake(0, 0, 320, 120) camera:camera];
    [mapView animateToCameraPosition:camera];
    mapView.delegate = self;
    mapView.myLocationEnabled = YES;
    [self.view addSubview:mapView];
    
    //getlocation method
    -(CLLocationCoordinate2D) getLocation{
    CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    [locationManager startUpdatingLocation];
    CLLocation *location = [locationManager location];
    CLLocationCoordinate2D coordinate = [location coordinate];
    
    return coordinate;
    }
    
  3. 正在为 map 上的当前位置创建标记。

     [[GMSGeocoder geocoder]         reverseGeocodeCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude) completionHandler:^(GMSReverseGeocodeResponse *response, NSError *error)
     {
     NSLog( @"Error is %@", error) ;
     NSLog( @"%@" , response.firstResult.addressLine1 ) ;
     NSLog( @"%@" , response.firstResult.addressLine2 ) ;
     GMSMarker *marker = [[GMSMarker alloc] init];
     marker.position = coordinate;
     marker.title = response.firstResult.addressLine1;
     marker.snippet = response.firstResult.addressLine2;
     marker.appearAnimation = kGMSMarkerAnimationPop;
     NSArray* parts = [response.firstResult.addressLine2 componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];
     locValueLabel.text = [parts objectAtIndex:0];
    
     marker.map = mapView;
     } ] ;
    

关于ios - 为 iOS 实现 Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20376357/

相关文章:

ios - 如何防止在 safari 移动浏览器上缩放(滚动)?

ios - 将数据导出/共享到另一个应用程序安装

javascript - Maps LatLng 不读取我的数据

javascript - 如何使用ajax请求刷新 map ?

ios - 音频队列 : Can't read raw data in AudioFileReadPackets

ios - @lvalue $T 5' is not identical to ' Swift 中的 AnyObject

ios - 如何在 Watchkit 中实现模糊背景图像,如 TuneIn 应用程序

ios - collectionView 中的单元格重用错误

iphone - iOS - 下载 HTML 网页,搜索内容并根据查询结果将文本设置为标签

javascript - 使用 AJAX 加载 Google Maps API...但多个实例仅加载一次