ios 在自定义纬度/经度创建一个新的 CLLocationCoordinate2D
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6739505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a new CLLocationCoordinate2D at custom Latitude/Longitude
提问by Karoly S
I feel bad for asking this because it seems to be such a simple thing to get hung up on, but I've looked at every relevant resource I could, tried as many of the combinations for solutions that i've seen others use, and nothing has worked...
我为问这个感到难过,因为这似乎是一件很简单的事情,但我已经查看了所有相关资源,尝试了我见过其他人使用的解决方案的尽可能多的组合,并且没有任何效果...
I am trying to iterate through some XML that I recieve and parse out the Latitude and Longitude of a coordinate in the XML, and store it in an array from which I will then plot it.
我试图遍历我收到的一些 XML 并解析出 XML 中坐标的纬度和经度,并将其存储在一个数组中,然后我将从中绘制它。
My problem is that no matter what type I use, how I cast it, what have you, xcode ALWAYS finds some sort of issue with it.
我的问题是,无论我使用什么类型,我如何投射它,你有什么,xcode 总是会发现某种问题。
Relevant part of my .h file:
我的 .h 文件的相关部分:
CLLocationCoordinate2D Coord;
CLLocationDegrees lat;
CLLocationDegrees lon;
@property (nonatomic, readwrite) CLLocationCoordinate2D Coord;
@property (nonatomic, readwrite) CLLocationDegrees lat;
@property (nonatomic, readwrite) CLLocationDegrees lon;
Relevant part of my .m file:
我的 .m 文件的相关部分:
else if ([elementName isEqualToString:@"Lat"]) {
checkpoint.lat = [[attributeDict objectForKey:@"degrees"] integerValue];
}
else if ([elementName isEqualToString:@"Lon"]) {
checkpoint.lon = [[attributeDict objectForKey:@"degrees"] integerValue];
}
else if ([elementName isEqualToString:@"Coord"]) {
checkpoint.Coord = [[CLLocation alloc] initWithLatitude:checkpoint.lat longitude:checkpoint.lon];
}
The current error that I am getting is: "Assigning to 'CLLocationCoordinate2D from incompatible type 'id''. I take that to mean that the return value of the initialization function is incorrect, but I have no idea why since its a built in function...
我得到的当前错误是:“从不兼容的类型‘id’分配给‘CLLocationCoordinate2D’。我认为这意味着初始化函数的返回值不正确,但我不知道为什么,因为它是一个内置函数...
I have also tried what would make the most sense to me that I saw someone else doing:
我还尝试了我看到其他人所做的对我来说最有意义的事情:
checkpoint.Coord = CLLocationCoordinate2DMake(checkpoint.lat, checkpoint.lon);
While that returns no immediate errors, when I try to build and run it gives me:
虽然这不会立即返回错误,但当我尝试构建和运行时,它给了我:
Undefined symbols for architecture i386: "_CLLocationCoordinate2DMake", referenced from: -[XMLParser parser:didStartElement:namespaceURI:qualifiedName:attributes:] in Checkpoint.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status
架构 i386 的未定义符号:“_CLLocationCoordinate2DMake”,引用自:-[XMLParser parser:didStartElement:namespaceURI:qualifiedName:attributes:] in Checkpoint.o ld:找不到架构 i386 collect2 的符号:ld 返回 1 退出状态
Any help/clarification/nudges in the right direction would be very much appreciated because I am very out of ideas at this point.
任何在正确方向上的帮助/澄清/推动将不胜感激,因为此时我非常没有想法。
回答by Firoze Lafeer
What made the most sense to you (CLLocationCoordinate2DMake) is correct. You just forgot to include the CoreLocation framework in your project.
对您来说最有意义的 (CLLocationCoordinate2DMake) 是正确的。您只是忘记在您的项目中包含 CoreLocation 框架。
And, as others have pointed out, your lat/lon in your file are probably not integers.
而且,正如其他人指出的那样,您文件中的经纬度可能不是整数。
回答by Pedro Rom?o
what i did was: first create a CLLocationCoordinate2D:
我所做的是:首先创建一个 CLLocationCoordinate2D:
CLLocationCoordinate2D c2D = CLLocationCoordinate2DMake(CLLocationDegrees latitude, CLLocationDegrees longitude);
my latitude and longitude are double types.
我的纬度和经度是双重类型。
in your Imports be sure Mapkit library is imported.
在您的导入中确保导入 Mapkit 库。
#import <MapKit/MapKit.h>
回答by Kal
This should work.
这应该有效。
CLLocationCoordinate2D center;
.....
else if ([elementName isEqualToString:@"Lat"]) {
center.latitude = [[attributeDict objectForKey:@"degrees"] doubleValue];
}
else if ([elementName isEqualToString:@"Lon"]) {
center.longitude = [[attributeDict objectForKey:@"degrees"] doubleValue];
}
回答by Joris Mans
try changing
尝试改变
[[attributeDict objectForKey:@"degrees"] integerValue]
into
进入
[[attributeDict objectForKey:@"degrees"] floatValue]
also
还
checkpoint.Coord = [[CLLocation alloc] ....
can't be correct as you defined Coord as being CLLocationCoordinate2D, which is
不可能正确,因为您将 Coord 定义为 CLLocationCoordinate2D,即
- not a CLLocation
- not a class but a struct
- 不是 CLLocation
- 不是一个类而是一个结构
what you should do is:
你应该做的是:
CLLocationCoordinate2D coordinate;
else if ([elementName isEqualToString:@"Lat"]) {
coordinate.latitude = [[attributeDict objectForKey:@"degrees"] floatValue];
}
else if ([elementName isEqualToString:@"Lon"]) {
coordinate.longitude = [[attributeDict objectForKey:@"degrees"] floatValue];
}
checkpoint.Coord = coordinate;