如何使用Google Maps SDK for iOS中的可拖动地图和固定标记获取位置地址

时间:2016-04-14 07:39:44

标签: ios google-maps

目前我正在开发像Uber这样的应用,我正在使用Google Maps SDK。

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

现在我正在寻找的是:如果用户应该移动地图(具有不同的位置)。我需要获得地址。我不想要GMSMarker拖动功能

当用户移动谷歌MAP相机位置时,我需要获取位置信息,如:Dolly app,Uber应用程序,Ola cabs等。

你能帮我解决一下如何克服这个问题

我做了一些R& D为此。我得到了一些参考链接,如:Select a position using draggable map and fixed marker in Google Maps SDK for iOS

2 个答案:

答案 0 :(得分:3)

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

  1. 首先,在地图视图的中心添加标记imageView。
  2. 从代理mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position
  3. 获取地图中心(position.target)的坐标
  4. 使用

    反转地对坐标进行地理编码

    [[GMSGeocoder geocoder] reverseGeocodeCoordinate:coordinate     completionHandler:^(GMSReverseGeocodeResponse *响应,NSError *错误){         GMSAddress * address = [response.results firstObject]; }];

答案 1 :(得分:0)

这对您来说是一个完美的答案。你看到我回答...

您需要在这里获取当前地址。

请打开此链接。

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

在此功能中,我们可以获取地图中心的纬度和经度。

How to move marker on the Google Map like Ola app

获取当前位置地址

- (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 Detected\n");
         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 Detected\n");
         //return;
         CountryArea = NULL;
     }
     /*---- For more results 
     placemark.region);
     placemark.country);
     placemark.locality); 
     placemark.name);
     placemark.ocean);
     placemark.postalCode);
     placemark.subLocality);
     placemark.location);
      ------*/
 }];
 }