我有两个NSString
S(地址和密钥)包含坐标(经度和纬度)的数字形式(34,56789 ...):注释上的MapView:坐标
NSString *key = [allKeys objectAtIndex:i];
NSObject *obj = [DictionaryMap objectForKey:key];
NSString *address = [NSString stringWithFormat:@"%@", obj];
CLLocationCoordinate2D anyLocation;
anyLocation.latitude = [address doubleValue];
anyLocation.longitude = [key doubleValue];
MKPointAnnotation *annotationPoint2 = [[MKPointAnnotation alloc] init]; annotationPoint2.coordinate = anyLocation;
annotationPoint2.title = @"Event";
annotationPoint2.subtitle = @"Microsoft's headquarters2";
[mapView addAnnotation:annotationPoint2];
..但是我不明白为什么它不能和坐标写在同一点上。我觉得这不工作:
[address doubleValue]
所以我试着用替换它:
location.latitude = NSNumber/NSString
,但它给出了一个错误。
UPDATE:
鉴于DID LOAD:
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
[self.mapView addGestureRecognizer:longPressGesture];
[mapView.userLocation setTitle:@"I am here"];
..then ...
-(void)handleLongPressGesture:(UIGestureRecognizer*)sender {
// This is important if you only want to receive one tap and hold event
if (sender.state == UIGestureRecognizerStateEnded)
{
[self.mapView removeGestureRecognizer:sender];
}
else
{
// Here we get the CGPoint for the touch and convert it to latitude and longitude coordinates to display on the map
CGPoint point = [sender locationInView:self.mapView];
CLLocationCoordinate2D locCoord = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
// Then all you have to do is create the annotation and add it to the map
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init]; annotationPoint.coordinate = locCoord;
annotationPoint.title = @"Microsoft";
annotationPoint.subtitle = @"Microsoft's headquarters";
[mapView addAnnotation:annotationPoint];
NSString *latitude = [[NSString alloc] initWithFormat:@"%f",locCoord.latitude];
NSString *longitude = [[NSString alloc] initWithFormat:@"%f", locCoord.longitude];
NSLog(latitude);
NSLog(longitude);
[[NSUserDefaults standardUserDefaults]setObject:latitude forKey:@"FolderLatitude"];
[[NSUserDefaults standardUserDefaults]setObject:longitude forKey:@"FolderLongitude"];
}
}
...我然后保存坐标的JSON文件,然后读他们从文件中。
'的NSNumber/NSString'没有任何意义的ObjC。什么是错误?你认为会发生什么?你能解释一下你想要完成什么吗?这不是很清楚。 –
不,我的意思是我先试着用NSNumber(不兼容的参数强),然后是NSString(同样的错误) – Alessandro