map-kitを使用してアプリケーションを開発するタスクが1つあります。
サーバーから複数のピンを取得していますが、ユーザーの現在の場所から1つのピンをドロップする必要があります。このユーザーの現在地のピンは緑色で、サーバーからのその他のピンは別の色である必要があります。これを行うにはどうすればよいですか?
もう1つの質問は、緯度と経度に若干の違いがあるため、互いにいくつかのピンを取得していることです。したがって、ピンが互いにドロップされる特定のポイントで、緯度と経度のピンのわずかな違いを処理する1つのボタン(ピンポップアップウィンドウ上)を指定したいので、ボタンは次のピンとすぐに通知しますボタンが押されると、ポップアップウィンドウはまだ選択されていない別のピンに移動し、次のピンも通知するポップアップウィンドウを開きます。これどうやってするの??
私はピンを作成するためにこのようなコードを使用しています
ユーザー位置ピンを取得するため
Place* current = [[[Place alloc] init] autorelease];
current.name = @"You are here.";
current.latitude = coordinate.latitude;
current.longitude = coordinate.longitude;
PlaceMark *from = [[[PlaceMark alloc] initWithPlace:current] autorelease];
[mapView addAnnotation:from];
サーバーロケーションピンを取得するため。
int s=1;
for (j=0 ; j < i - 1 ; j++)
{
//points = [[NSString alloc] initWithFormat:@"point%d",s];
reports = [NSArray arrayWithArray:lat];
NSString *titles = [[NSString alloc] initWithFormat:@"%@",[tit objectAtIndex:j]];
NSString *description = [[NSString alloc] initWithFormat:@"%@",[des objectAtIndex:j]];
float latitude=[[lat objectAtIndex:j] floatValue];
float longitude=[[lon objectAtIndex:j] floatValue];
Place* home = [[[Place alloc] init] autorelease];
home.name = [NSString stringWithFormat:@"%@",titles];
home.description = [NSString stringWithFormat:@"%@",description];
home.latitude = latitude;
home.longitude = longitude;
PlaceMark *from = [[[PlaceMark alloc] initWithPlace:home] autorelease]; [mapView addAnnotation:from];
s++;
[self centerMap];
}
そこにポップアップウィンドウを作成するためのこのコード。
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation{
if (annotation == mapView.userLocation)
return nil;
MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];
if (pin == nil)
pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: @"asdf"] autorelease];
else
pin.annotation = annotation;
pin.userInteractionEnabled = YES;
UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[disclosureButton setFrame:CGRectMake(0, 0, 30, 30)];
pin.rightCalloutAccessoryView = disclosureButton;
pin.pinColor = MKPinAnnotationColorRed;
pin.animatesDrop = YES;
[pin setEnabled:YES];
[pin setCanShowCallout:YES];
return pin;}
イベントを処理するためのこのコードは、ピンがボタンアクションを呼び出していることを意味します。
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{ nslog (do something)
}
私のすべてのコードは正しく機能しています。私は上記の質問に答えたいだけです..plsは私を助けます