问题描述
我正在尝试在两个位置之间进行两个绘制路线,为此,我从Google Map API Web Service获取所有点.(JSON
输出格式).解析JSON
数据和删除点后,我将所有点存储在NSMutableArray
上.每个索引数组都包含这种类型的值.
I am trying two draw route between two location,For that I Fetch all the points from Google Map API Web Service.(JSON
Output Format). After parsing JSON
Data and De cording points i stored all points on NSMutableArray
.Each array of index contains this type of values.
"<+10.90180969, +76.19167328> +/- 0.00m (speed -1.00 mps / course -1.00) @ 12/04/12 10:18:10 AM India Standard Time",
现在,我想分隔纬度和经度值.
Now i want to separate latitude and longitude values.
latitude : +10.90180969
longitude : +76.19167328
如何从数组的每个索引中获取此值?
How to get this values from each index of array?
推荐答案
这里的内容非常粗略,我认为它是蛮荒的解决方法
Here is something in a very crude form and I guess its a brute solution
NSString* str = @"<+10.90180969, +76.19167328> +/- 0.00m (speed -1.00 mps course -1.00) @ 12/04/12 10:18:10 AM India Standard Time";
NSArray* arr = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
if ([arr count] > 1) {
NSString* coordinateStr = [arr objectAtIndex:1];
NSArray* arrCoordinate = [coordinateStr componentsSeparatedByString:@","];
NSLog(@"%@",arrCoordinate);
}
查看显示您正在打印CLLocation对象" someObject "的描述的字符串,您还可以访问纬度和经度,例如
Looking at the string it shows that you are printing the description of a CLLocation object "someObject" , You can also access the latitude and longitude such as
CLLocationCoordinate2D location = [someObject coordinate];
NSLog(@" \nLatitude: %.6f \nLongitude: %.6f",location.latitude,location.longitude);
输出将为:纬度:28.621873经度:77.388897
OutPut will be : Latitude: 28.621873 Longitude: 77.388897
但这不会给您显示符号,例如"+"或-"
but this won't give you the signs i.e "+" , or "-"
希望有帮助.
这篇关于如何从JSON输出中分离出经度和纬度值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!