iPhoneのGoogleマップにピンの注釈をデザインして、ピンをドラッグしてピンをドラッグしてGoogleマップに配置して位置を設定できるようにしたいその選択の。
ユーザーがピンを置くと、そのピンに対応するロケーション座標とロケーション名を取得します。 iPhoneでこれをどのように開発するか提案してください。
ありがとうiPhoneの動的ピン注釈を使用してGoogleマップから場所を選択
答えて
の方法あなたは(私が作成した)MKMapViewDelegateプロトコルとLongPressGestureAwareからメソッドを実装する必要がためユーザーが画面をタップして保持すると、ピンをマップ上にドロップします。
注釈はMKAnnotationとMKReverseGeocoderDelegateプロトコルを実装する必要があります。
私はあなたを助けることができる私のコードの一部を貼り付けます。
SimpleMapAnnotationViewController.h:
@interface SimpleMapAnnotationViewController : TTViewController<LongPressGestureAware, MKMapViewDelegate> {
SimpleMapAnnotation *_dropPin;
MKPinAnnotationView *_pinView;
}
SimpleMapAnnotationViewController.m:
#pragma mark -
#pragma mark LongPressGestureAware
-(void) initLongPressGestureRecognizer {
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
[self.map addGestureRecognizer:longPressGesture];
[longPressGesture release];
}
-(void)handleLongPressGesture:(UIGestureRecognizer*)sender {
if([sender isMemberOfClass:[UILongPressGestureRecognizer class]] && (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateBegan)) {
[self.map removeGestureRecognizer:sender]; //avoid multiple pins to appear when holding on the screen
}
CGPoint point = [sender locationInView:self.map];
CLLocationCoordinate2D theCoordinate = [self.map convertPoint:point toCoordinateFromView:self.map];
self.dropPin = [[[SimpleMapAnnotation alloc] initWithCoordinate:theCoordinate] autorelease];
[self.map addAnnotation:self.dropPin];
[self performSelector:@selector(selectInitialAnnotation) withObject:nil afterDelay:0.5];
}
-(void)selectInitialAnnotation {
[self.map selectAnnotation:[self.map.annotations objectAtIndex:0] animated:YES];
}
#pragma mark -
#pragma mark MKMapViewDelegate
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation {
if (annotation == self.map.userLocation){
return nil; //default to blue dot
}
MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"annotation_ID"];
if (pin == nil) {
pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"annotation_ID"] autorelease];
} else {
pin.annotation = annotation;
}
pin.canShowCallout = YES;
pin.draggable = YES;
pin.animatesDrop = YES;
pin.pinColor = MKPinAnnotationColorGreen;
self.pinView = pin;
self.dropPin.pinView = self.pinView;
return pin;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState {
//NSArray *annotations = self.map.annotations;
if (oldState == MKAnnotationViewDragStateDragging) {
SimpleMapAnnotation *annotation = (SimpleMapAnnotation *)annotationView.annotation;
[annotation updateSubtitle];
}
if(newState == MKAnnotationViewDragStateEnding) {
NSLog(@"drag finish");
}
}
SimpleMapAnnotation.h
@interface SimpleMapAnnotation : NSObject <MKAnnotation, MKReverseGeocoderDelegate> {
CLLocationCoordinate2D _coordinate;
NSString *_title;
NSString *_subtitle;
MKPinAnnotationView *_pinView;
}
SimpleMapAnnotation.m
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate {
self.coordinate = coordinate;
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:self.coordinate];
geoCoder.delegate = self;
[geoCoder start];
self.subtitle = [NSString stringWithFormat:@"%f %f", self.coordinate.latitude, self.coordinate.longitude];
return self;
}
#pragma mark -
#pragma mark MKReverseGeocoderDelegate
// this delegate is called when the reverseGeocoder finds a placemark
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
MKPlacemark * myPlacemark = placemark;
NSString *address = [myPlacemark.addressDictionary objectForKey:(NSString*) kABPersonAddressStreetKey];
self.title = address;
}
// this delegate method is called if an error occurs in locating your current location
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"locationManager:%@ didFailWithError:%@", manager, error);
}
// this delegate is called when the reversegeocoder fails to find a placemark
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
//invalid place
}
In - (void)handleLongPressGesture:(UIGestureRecognizer *)送信者 (sender.state == UIGestureRecognizerStateBegan)の場合、gestureRecognizerは削除されます。マップ上に次の注釈を永久に追加することはできませんか? – akshay1188
@ akshay1188正確に、これを行うことで、地図上に1つのピンしかないことが保証されます。このピンは、ユーザーが別の場所にドラッグアンドドロップすることができます。画面上をタップ&ホールドするときにこの行を削除すると、ピンの束が表示されます。 – yeforriak
あなたはMaps Annonationsのドキュメントを読むことができます。 toCoordinateFromView: Here is the linkあなたは場所がconvertPointを使用してのMapView内の任意の点から座標を取得することができます
あなたのビューコントローラでのMapView
「annotation.coordinate」から直接座標を取得することもできます – Rayfleck
- 1. iPhoneのMapView注釈/ピン
- 2. コントロールMapKitピン注釈タップ選択
- 3. 使用iPhoneの場所では、Googleマップ
- 4. Googleマップのアクティビティから選択した場所を取得
- 5. GoogleマップのKMLファイルから注釈用の赤いピンが多すぎます
- 6. Swiftでユーザーの場所の注釈を選択する方法
- 7. 注釈(ピン)を現在の場所にドロップする
- 8. MKMapView(注釈と場所) - iPhone開発
- 9. Googleマップ - Facebookの場所偽の場所JSONを使用して
- 10. MapKitを使用して、ピンの注釈(注釈)にカスタムUIViewを表示する
- 11. 複数の場所を使用してFirebaseデータベースから選択
- 12. MapKitとUIGestureRecognizerを使用して注釈ピンを追加する
- 13. 選択したセルに応じて、マップビューに注釈ピンを追加する
- 14. Android Googleマップのオーバーレイバルーン/注釈
- 15. どのJavaScriptがGoogleマップapi 3の場所の自動補完ドロップダウンからの選択をシミュレートしますか?
- 16. マップをユーザーの場所と注釈にズームする(スウィフト2)
- 17. テキストボックスにGoogle APIから場所を選択した後のイベント
- 18. Googleマップ以外の場所でのピンのクリックの詳細
- 19. 注釈を使用する動的AuditLog
- 20. 現在の場所、MapKit、Swift、iOS10にピン注釈を描画する方法
- 21. 静的Googleマップ2ピン
- 22. Googleマップから場所を選んでアンドロイドデバイスに保存
- 23. nosqlunit注釈@UsingDataSet場所
- 24. Googleマップを使用してピンと店舗の場所を追加できるようにする
- 25. ピン注釈のコールアウトボタンのテキスト
- 26. 複数の注釈を含むGoogleマップ
- 27. 私は場所のピンでGoogleマップを使用したいと私は特定のボタンをクリックしたときにその場所に移動したい。 .NET
- 28. カスタム注釈ピンがiphoneのmkmapviewのshowuserlocationに干渉する
- 29. UserDefaultsを使用してマップの注釈を保存する
- 30. Splinterを使用して動的メニューから選択する
[この回答](http://stackoverflow.com/a/3999583/467105)少しを助けるかもしれません。 "location name"とは、新しい座標を逆ジオコーディングしたいということです。 CLGeocoder(iOS5)またはMKReverseGeocoder(iOS4)を参照してください。 – Anna