在地图上获取触摸位置

时间:2015-06-04 11:39:21

标签: ios mapkit

我正在使用以下代码在地图上查找触摸位置的纬度和经度 -

-(void)handlePressRecognizer:(UIGestureRecognizer *)gestureRecognizer {
    for (PointAnnotation *ann in [mMapview annotations]) {
        if ([ann isKindOfClass:[PointAnnotation class]]) {
            [mMapview removeAnnotation:ann];
        }
    }
    [mMapview removeAnnotations:[mMapview annotations]];
    CGPoint touchPoint = [gestureRecognizer locationInView:mMapview];
    CLLocationCoordinate2D touchMapCoordinate =
    [mMapview convertPoint:touchPoint toCoordinateFromView:gestureRecognizer.view];
    if (gpsLocation != nil) {
        gpsLocation = nil;
    }
    gpsLocation = [[CLLocation alloc]initWithLatitude:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude];
    [self performSelector:@selector(showLoadingView) withObject:nil afterDelay:0.001];
    [self performSelector:@selector(getGoogleAddressFromLocation:) withObject:gpsLocation afterDelay:0.1];


}

我正在将这些lat / long传递给谷歌API以查找地址,但谷歌给了我错误的位置和地址。

这是屏幕截图 -

enter image description here

请帮助找出这个问题。

1 个答案:

答案 0 :(得分:0)

我使用谷歌地图SDK中的以下代码来获取点击位置 -

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
    NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);

    [mMapview clear];
    gpsLocation = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];

}

使用以下代码我将丢弃该位置的引脚 -

    GMSMarker *marker = [[GMSMarker alloc]init];

    marker.title = [responseDict valueForKey:@"address"];
    marker.snippet = [responseDict valueForKey:@"country"];
    self.addressString = [responseDict valueForKey:@"address"];
    marker.position = gpsLocation.coordinate;

    marker.map = mMapview;
    [mMapview setSelectedMarker:marker];

使用mapkit,谷歌没有给我正确的点击位置,但谷歌地图的工作就像一个魅力。