iphone - 如何将文本的 nsstring 值转换为 objective-c 中的 CLLocationCoordinate2D for google map

标签 iphone objective-c google-maps

我想给用户一个选项,让他可以在 iPhone 的谷歌地图中输入他想搜索的位置名称。当用户输入特定 map 的位置名称时。

现在我通过固定对象纬度和经度中坐标的值来做到这一点。

CLLocationCoordinate2D location=mapView.userLocation.coordinate;

location.latitude=19.14;
location.longitude=73.10;

有没有办法在文本中给出这个坐标的值并将其转换为 CLLocationCoordinate2D 的值?

最佳答案

我不是很清楚你的问题,但如果你想将一个 NSString 转换成一个 CLLocationCoordinate2D 你可以使用以下方法:

{
    [self useLocationString:@"19.14,73.10"];
}

- (void) useLocationString:(NSString*)loc
{
    // the location object that we want to initialize based on the string
    CLLocationCoordinate2D location;

    // split the string by comma
    NSArray * locationArray = [loc componentsSeparatedByString: @","];        

    // set our latitude and longitude based on the two chunks in the string
    location.latitude = [[[NSNumber alloc] initWithDouble:[[locationArray objectAtIndex:0] doubleValue]] autorelease];
    location.longitude = [[[NSNumber alloc] initWithDouble:[[locationArray objectAtIndex:1] doubleValue]] autorelease];

   // do something with the location
}

此代码不检查字符串的有效性,您可以检查从 componentsSeparatedByString 返回的 NSArray

关于iphone - 如何将文本的 nsstring 值转换为 objective-c 中的 CLLocationCoordinate2D for google map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2131567/

相关文章:

iphone - 有没有办法改变 scrollRectToVisible 的速度?

iphone - UITableViewscrollToRowAtIndexPath在iOS 7上滚动到估计RowHeight错误的偏移量

iphone - 如何转换 NSString 中的日期时间格式?

javascript - Google map 标记未通过 ajax 动态显示

javascript - 在谷歌地图中添加新标记之前删除以前的标记

iphone - 尝试调整 UITableView 的大小会导致屏幕出现一秒钟的故障,然后才能正确显示

iphone - 有没有提供建议词的api?

ios - 如果我使用委托(delegate)在 View Controller 之间进行通信,我会承担什么风险?

objective-c - 如何知道 NSURLSessionDataTask 的 for 循环何时完成

google-maps - Google Maps API-Radius是否使用Places搜索标记?