ユーザーに2つのオプションを提供するアプリケーションがあります。1.GPSを使用して現在地を選択します。2。現在地を手動で入力します。
私が欲しいのは、ユーザーが最初のオプションを選択したとき、現在の場所の青いアニメーションアイコンを表示する必要があり、ユーザーが2番目のオプションを選択したとき、現在の場所の独自のカスタムアイコンを表示する必要があります。
出来ますか?提案は大歓迎です。
ありがとう。
ユーザーに2つのオプションを提供するアプリケーションがあります。1.GPSを使用して現在地を選択します。2。現在地を手動で入力します。
私が欲しいのは、ユーザーが最初のオプションを選択したとき、現在の場所の青いアニメーションアイコンを表示する必要があり、ユーザーが2番目のオプションを選択したとき、現在の場所の独自のカスタムアイコンを表示する必要があります。
出来ますか?提案は大歓迎です。
ありがとう。
まず、例isInGPSModeのブール変数を設定します
次のコードを適用します
if(isInGPSMode==TRUE)
{
mapViewHome.showsUserLocation=TRUE;
}
else
{
mapViewHome.showsUserLocation=FALSE;
}
マップビューデリゲートを次のように処理します
- (MKAnnotationView *) mapView:(MKMapView *)mapView1 viewForAnnotation:(id <MKAnnotation>) annotation
{
if(annotation==mapViewHome.userLocation)
{
return nil;
}
addAnnonation *tempAnnonation=(addAnnonation *)annotation;
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorRed;
return annView;
}
詳細については、リンク http://developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.htmlを参照してください。
お役に立てれば
SwiftでのRupeshのソリューション:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
// Keep default pin for user location
if myMapView.userLocation.isEqual(annotation) {
return nil;
}
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier("pin") as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "pin")
pinView!.canShowCallout = true
pinView!.animatesDrop = true
pinView!.pinColor = .Red
}
else {
pinView!.annotation = annotation
}
return pinView
}