2017-10-25 14 views
0

この質問は何千もの時間が掛かっていることを知っています。多くのコードを検索していましたが、機能しませんでした。私はそれの下に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; 
} 
+0

あなたは 'addAnnotation'メソッドを呼び出しましたか? –

+0

はい私のコードでチェックしてください。 @KosukeOgawa – Oneeb

+0

私は 'あなたのコード内addAnnotation' ;-(終わりMKAnnotationviewための方法で –

答えて

0

、これです。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    NSLog(@"didUpdateToLocation: %@", newLocation); 

    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
    annotation.coordinate = newLocation.coordinate; 
    [self.mapView addAnnotation:annotation]; 
} 
+0

デフォルトのピンの代わりに私自身のカスタムイメージを使用するにはどうすればいいですか?小塚康介 – Oneeb

+0

viewDidLoadメソッドに 'self.mapView.delegate = self; ? –

+0

@interface YourViewController() ' –

関連する問題