我有以下代码:添加注释值
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.0005;
span.longitudeDelta=0.0005;
CLLocationCoordinate2D location = mapView.userLocation.coordinate;
for (int i = 0; i < [appDelegate.markers count]; i++) {
marker *aMarker = [appDelegate.markers objectAtIndex:i];
location.latitude = [[aMarker.lat objectAtIndex:i] floatValue];
location.longitude =[[aMarker.lng objectAtIndex:i] floatValue];
region.span=span;
region.center=location;
if(addAnnotation != nil)
{
[mapView removeAnnotation:addAnnotation];
[addAnnotation release];
addAnnotation = nil;
}
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
[mapView addAnnotation:addAnnotation];
}
我在XMLparser
类解析的经度和纬度。现在我想在Map上的buttonclick事件上添加注释。有人可以纠正我的代码吗?
我在尝试这么多后没有在地图上找到注释... –
当你运行它时会发生什么?为什么使用索引'i'来访问'aMarker'对象中的'markers'数组_和'lat'和'lng'?为什么你将'location'设置为'userLocation',然后用'markers'的值覆盖它?你对“地区”做了什么?你应该在调用mapView addAnnotation之前记录'location'的值。另外,'addAnnotation'对于注释变量来说是一个非常混乱的名字。 – Anna
你解决了你的问题吗?如果不是,告诉我什么是位置,它是否是Cllocation点数组?只有当你的位置是一个CLLocation数组时,你才会得到注释。 – iCoder4777