我已經得到了緯度和XML解析經度我怎麼能顯示在地圖上MapAnnotation(PIN),請幫我....我有經度和經度我怎樣才能在地圖視圖中顯示註釋?
0
A
回答
0
首先你要創建MKAnnotation協議類(這裏MyAnnotation類實現MKAnnotation協議)。這個類應該包括lat,long,title,subtitle以及任何你想要的。
其次,在您的視圖控制器,你要顯示的腳,你會實現這個代碼,
AnnObj = [[MyAnnotation alloc] init];
AnnObj.latitude = [[latitude objectAtIndex:storyIndex] floatValue];
AnnObj.longitude = [[longitude objectAtIndex:storyIndex] floatValue];
MKCoordinateRegion region;
region.center = location;
MKCoordinateSpan span;
region.center.latitude = [[latitude objectAtIndex:storyIndex] floatValue];
region.center.longitude = [[longitude objectAtIndex:storyIndex] floatValue];
span.latitudeDelta = 0.0005;
span.longitudeDelta = 0.0005;
region.span = span;
[mapview setRegion:region animated:TRUE];
AnnObj.title = titleString;
AnnObj.subTitle = subTitleString;
NSString * titleString = [[buildingNames objectAtIndex:storyIndex] stringByReplacingOccurrencesOfString:@"\n\t" withString:@""];
[eventPoints addObject:AnnObj];
[mapview addAnnotations:eventPoints];
Third, Implement the MKAnnotation delegate method,
- (MKAnnotationView *)mapView: (MKMapView *)lmapView viewForAnnotation:(id <MKAnnotation>) annotation {
if (lmapView.userLocation == annotation){
return nil;
}
MKAnnotationView* myCusAnn = (MKAnnotationView*)[lmapView dequeueReusableAnnotationViewWithIdentifier:@"eventview"];
if(myCusAnn == nil)
{
myCusAnn = [[[ MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"eventview"] autorelease];
}
myCusAnn.canShowCallout = YES;
[myCusAnn setEnabled:YES];
return myCusAnn;
}
我希望這會幫助你。
1
- 創建實現MKAnnotation協議的新類。這將保存緯度/經度,並且還會有一個標題和描述,如果您在地圖上渲染註釋後選擇註釋,將會顯示該標題和描述。
顯示地圖的視圖控制器需要實現MKMapViewDelegate協議的 -
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation;
方法。這種方法中的代碼看起來像底部的代碼(對於格式不好的道歉,我無法在這裏或底部得到正確的答案)。然後在你的控制器代碼某些時候,你需要調用沿
[self.mapView addAnnotation: annotation];
線,其中註釋是在步驟1中創建自定義的註釋類的實例的東西,與緯度/經度設置等最後,爲了讓viewForAnnotation方法得到正確調用,並且在界面構建器中很容易丟失,請確保您將MKMapView的委託出口設置爲您的控制器(實現MKMapViewDelegate協議)
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation { static NSString *AnnotationViewIdentifier = @"annotationViewIdentifier"; MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier: AnnotationViewIdentifier]; if (annotationView == nil) { annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: AnnotationViewIdentifier] autorelease]; // This is all optional and depends on your requirements annotationView.animatesDrop = NO; annotationView.canShowCallout = YES; annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; annotationView.enabled = YES; annotationView.pinColor = MKPinAnnotationColorGreen; } return annotationView; }
相關問題
- 1. Bing地圖。我怎樣才能得到緯度和經度的地址?
- 2. 我無法使用緯度和經度在地圖視圖中添加註釋
- 3. 我怎樣才能獲得的緯度和經度從JSON谷歌地圖
- 4. iOS - 我怎樣才能返回經度和緯度?
- 5. 角谷歌地圖使用控制器我怎樣才能得到(經度和緯度)當前地圖的中心獲取地圖的經緯度中心
- 6. 我怎樣才能找到當前經度和使用HTML5
- 7. 地圖緯度和經度在android中顯示在海中?
- 8. 如何顯示在具有緯度和經度的iframe地圖
- 9. Python:Django:我怎樣才能找到用戶的緯度和經度,以便我可以顯示用戶的位置?
- 10. 地圖經度和緯度
- 11. 谷歌地圖API - 我怎樣才能獲得特定國家的緯度和經度
- 12. 我怎樣才能獲得緯度和經度值從UDP數據包的C#
- 13. 用於在地圖上顯示地址的緯度和經度
- 14. 我怎樣才能顯示我的位置谷歌地圖android
- 15. 通過XML解析試圖分析緯度和經度和註釋,我在我的字典裏已經
- 16. 我怎樣才能在圖
- 17. 我怎樣才能在網格視圖
- 18. 我怎樣才能在網格視圖
- 19. 我怎樣才能找到測量的視圖高度?
- 20. 我怎樣才能顯示一個刻度和一個JButton
- 21. 如何在Android地圖上顯示經度和海拔高度?
- 22. 以min爲單位顯示Google地圖緯度/經度爲max緯度/經度
- 23. 我怎樣才能加載視圖
- 24. 我怎樣才能當視圖推
- 25. 我怎樣才能UIToolbar當前視圖
- 26. 如何在地圖上顯示地圖的緯度和經度(Android Studio)
- 27. 我已經有日誌文件。我怎樣才能做出它的圖表?
- 28. Javascript和bing地圖,顯示地址的地圖(不使用經度/緯度)
- 29. 將角度地圖轉換爲經度谷歌地圖中的緯度/經度
- 30. Javascript谷歌地圖,以緯度和經度座標顯示標註
感謝您的回答.. – 2010-06-07 05:55:11
也許您可以編輯您的答案,以便更好地突出顯示代碼。 – testing 2010-10-05 15:58:43