如何在iOS版谷歌地图SDK中使用可拖动地图和固定标记获取位置地址



目前我正在开发一款类似优步的应用程序,我正在使用谷歌地图SDK。

我的问题是:目前我在UITextField中显示用户的当前位置,同时我也在谷歌地图上显示GMSMarker。

现在,我正在寻找的是:如果用户应该移动地图(不同的位置)。我需要得到地址。我不想要GMS标记拖动功能

当用户移动谷歌地图摄像头位置时,我需要获得位置信息,如:Dolly应用程序、优步应用程序、Ola出租车等

你能帮我解决这个问题吗

我做了一些R&D。我得到了一些参考链接,比如:在iOS版的谷歌地图SDK中使用可拖动地图和固定标记选择位置

不确定这是否是您想要实现的,但:

  1. 首先,在地图视图的中心添加一个标记imageView
  2. 从代理mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position获取地图中心(position.target)的坐标
  3. 使用对坐标进行反向地理编码

    [[GMSGeocoder geocoder]reverseGeocodeCoordinate:坐标completionHandler:^(GMSReverseGeocodeResponse*响应,NSError*错误){GMSAddress*address=[响应.results第一对象];}];

这是您的完美答案。你看我的回答。。。

在这里,您需要处理以获取当前地址。

请打开此链接。

- (void) mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position { }

在这个函数中,我们可以得到地图中心的纬度和经度。

如何在谷歌地图上移动标记像Ola应用

获取当前位置地址

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
currentLocation = [locations objectAtIndex:0];
[locationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error)
 {
     if (!(error))
     {
         CLPlacemark *placemark = [placemarks objectAtIndex:0];
         NSLog(@"nCurrent Location Detectedn");
         NSLog(@"placemark %@",placemark);
         NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
         NSString *Address = [[NSString alloc]initWithString:locatedAt];
         NSString *Area = [[NSString alloc]initWithString:placemark.locality];
         NSString *Country = [[NSString alloc]initWithString:placemark.country];
         NSString *CountryArea = [NSString stringWithFormat:@"%@, %@", Area,Country];
         NSLog(@"%@",CountryArea);
     }
     else
     {
         NSLog(@"Geocode failed with error %@", error);
         NSLog(@"nCurrent Location Not Detectedn");
         //return;
         CountryArea = NULL;
     }
     /*---- For more results 
     placemark.region);
     placemark.country);
     placemark.locality); 
     placemark.name);
     placemark.ocean);
     placemark.postalCode);
     placemark.subLocality);
     placemark.location);
      ------*/
 }];
 }

最新更新