我想要做的是,我想要在用戶當前位置(圖像的縮略圖視圖)插入圖像,我有用戶當前位置,我已經設法插入MKMapView上的UIImageView,並且還能夠在其上顯示圖像。如何在MKMapView上的用戶當前位置添加UIImageView
但我無法找到/所做的事是將圖像放在用戶的當前位置。
我們如何在MKMapView的用戶當前位置添加UIImageView,以便圖像出現在用戶的當前位置。
任何想法......?
感謝您的時間..! :)
我想要做的是,我想要在用戶當前位置(圖像的縮略圖視圖)插入圖像,我有用戶當前位置,我已經設法插入MKMapView上的UIImageView,並且還能夠在其上顯示圖像。如何在MKMapView上的用戶當前位置添加UIImageView
但我無法找到/所做的事是將圖像放在用戶的當前位置。
我們如何在MKMapView的用戶當前位置添加UIImageView,以便圖像出現在用戶的當前位置。
任何想法......?
感謝您的時間..! :)
在最初定義UIImage *selectedImage
您.h
文件。 (使用UIImagePickerController
了點。)應用其委託的方法來從相機膠捲拿到所選圖像:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
selectedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
,然後分配相同UIImage
,而不是「您的用戶形象」在viewForAnnotation
方法,即
userannotationView.image = selectedImage;
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]]) {
MKAnnotationView *userannotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
userannotationView.image = [UIImage imageNamed:@"your user image.png"];
userannotationView.draggable = YES;
userannotationView.canShowCallout = YES;
return userannotationView;
}else {
// your code to return annotationView or pinAnnotationView
}
但是是否可以從相機膠捲分配圖像到註釋視圖..? – Shailesh
您可以利用Core Location框架來確定用戶的當前位置。您將獲取用戶的當前位置作爲經度和緯度(座標)。一旦你有了這個,你可以在座標的地圖視圖上添加一個註解(MKAnnotationView
的一個實例)。
要知道如何確定用戶的位置 - Getting user's current location
要在地圖上添加註解 - Annotating Maps
編輯:對於註解視圖
因此,而不是使用UIImage視圖,我應該使用註釋的目的..!但是是否可以將相機膠捲的圖像分配給註釋視圖..? – Shailesh
我們可以指定自定義圖像註釋視圖。看看[MKAnnotationView](http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6-SW1 )類參考。它有一個'image'屬性。您可以將該圖像設置爲您的自定義圖像,並在' - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(ActivityAnnotation *)annotation'委託方法中使用它。我在回答的編輯部分添加了一篇文章。 – 2012-09-25 10:04:52
謝謝..把這個想法..! :) – Shailesh
這就是我正在尋找的。謝謝@AppleDelegate – Shailesh
如果遇到任何問題,我會回覆。 – Shailesh