この質問は何千もの時間が掛かっていることを知っています。多くのコードを検索していましたが、機能しませんでした。私はそれの下にmapkitを持っている現在の場所を表示するボタンがありますが、私はそれを何も表示されず、マップピンのために自分のカスタムイメージを設定しているが、それも表示されません現在の場所とカスタム地図のピン画像
場所、カスタム地図ピン画像の
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
NSString *longi = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
NSLog(@"Longi %@",longi);
NSString *lat = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
NSLog(@"Longi %@",lat);
}
}
私のコードは、私はあなたがdidUpdateToLocationでaddAnnotation
を呼ぶべきだと思い
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKAnnotationView *view=[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"annoView"];
if (!view) {
view=[[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"annoView"];
if ([annotation isKindOfClass:[MKUserLocation class]]) {
return nil;
}else{
view.image=[UIImage imageNamed:@"car_marker.png"];
view.canShowCallout=YES;
}
}
return view;
}
あなたは 'addAnnotation'メソッドを呼び出しましたか? –
はい私のコードでチェックしてください。 @KosukeOgawa – Oneeb
私は 'あなたのコード内addAnnotation' ;-(終わりMKAnnotationviewための方法で –