gpt4 book ai didi

ios - 如何获得中心谷歌地图iOS的经纬度

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

我正在使用 Storyboard构建一个 iOS 应用程序。我在我的应用程序中集成了谷歌地图,并在点击时获取位置地址。

我想在滚动 map 的 map 中心实现一个图钉,图钉将移动并提供与 Uber 或 Ola Cabs 应用中相同的位置地址。

有人能帮我实现这个吗,我找到了一个教程(http://www.raywenderlich.com/81103/introduction-google-maps-ios-sdk-swift),但速度很快,但我必须在 objective-c 中实现。

这是我的代码:

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate{

// coordinate contains your coordinate :)

NSLog(@"did tap at coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude);

NSString *address=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&key=AIzaSjhsdfg67tahdsg8981k8_5aJoZps",coordinate.latitude, coordinate.longitude];

NSURL *url=[NSURL URLWithString:address];

NSData* data = [NSData dataWithContentsOfURL:url];

if ((unsigned long)data.length > 3) {

// NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSString *file=@"/Data.json";

[data writeToFile:file atomically:YES];

NSArray *ys_avatars = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

NSLog(@"array=%@",ys_avatars);

NSLog(@"status====%@",[ys_avatars valueForKey:@"status"]);

if([[ys_avatars valueForKey:@"status"] isEqual: @"OK"]){

NSArray *results=[ys_avatars valueForKey:@"results"];

NSLog(@"formatted_address====%@",[results valueForKey:@"formatted_address"] );

NSArray *address=[results valueForKey:@"formatted_address"];

NSLog(@"add=%@",address[0]);

_myAddress.text=address[0];

}

}

}

最佳答案

我不能评论所以回答你的问题,你可以通过这种方式获得 map 中心的纬度和经度:

    - (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position
{
double latitude = mapView.camera.target.latitude;
double longitude = mapView.camera.target.longitude;

CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longitude);


marker.position = center;

}

关于ios - 如何获得中心谷歌地图iOS的经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27068668/

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