gpt4 book ai didi

ios - 为 ios 实现谷歌地图

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:09:09 25 4
gpt4 key购买 nike

我已经给出了苹果 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 实现谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20376357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com