2016-05-04 4 views
2

Es gibt zwei Dateien .h und .m, die vollständigen Code haben, helfen Sie mir bitte, das Problem herauszufinden, warum Markierung nicht auftaucht. Ich habe Pod-Datei und googlemap sdk sowie installiert. Alles funktioniert gut, aber nur Markierungen werden nicht angezeigt, ich habe auch Werte im Protokoll gedruckt. Sie funktionieren gut, aber keine Markierung oder Anmerkung auf der Karte.Anmerkung oder Markierung zeigt nicht auf Google Karte

.h-Datei

#import <UIKit/UIKit.h> 
#import <GoogleMaps/GoogleMaps.h> 


@interface ViewController : UIViewController<GMSMapViewDelegate>{ 
NSArray *addressArray; 
NSArray *name; 
__weak IBOutlet UIView *loaderView; 

} 
@property (strong, nonatomic) IBOutlet GMSMapView *mapView; 
@property (strong, nonatomic) ViewController *calloutView; 
@property (strong, nonatomic) UIView *emptyCalloutView; 

@end 

.m-Datei

#import "ViewController.h" 
#import "SimplestGoogleMapApp-Prefix.pch" 
#import <GoogleMaps/GoogleMaps.h> 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
[super viewDidLoad]; 
self.mapView.myLocationEnabled=YES; 
self.mapView.mapType=kGMSTypeNormal; 
self.mapView.settings.compassButton=YES; 
self.mapView.settings.myLocationButton=YES; 
self.mapView.delegate=self; 
[self addMarlerToMap]; 

} 
-(void)addMarlerToMap{ 
NSURL *kAPIURL = [NSURL URLWithString:@"abcURl"]; 

NSString *jsonString = @"data={some data}"; 

NSData *JSONData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; 

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:kAPIURL]; 
request.HTTPMethod = @"POST"; 
request.HTTPBody = JSONData; 

NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request 
                  completionHandler:^(NSData *data, 
                        NSURLResponse *response, 
                       NSError *error) 
           { 
            if (!error) 
            { 
             NSError *JSONError = nil; 

             NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data 
                           options:0 
                            error:&JSONError]; 
             NSLog(@"%@",dictionary); 
             if (JSONError) 
             { 
              NSLog(@"Serialization error: %@", JSONError.localizedDescription); 
             } 
             else 
             { 

              dispatch_async(dispatch_get_main_queue(), ^{ 
           addressArray = dictionary[@"data"][@"centers"]; 


       loaderView.hidden = true; 
     UIImage *pinImage = [UIImage imageNamed:@"map_gym"]; 

     for(int i=0;i<=[addressArray count];i++){ 
     self.view = _mapView; 
     NSString *lat = [[addressArray objectAtIndex:i] objectForKey:@"lat"]; 
     NSString *lon = [[addressArray objectAtIndex:i] objectForKey:@"lng"]; 
       double lt=[lat doubleValue]; 
     double ln=[lon doubleValue]; 
     NSString *name = [[addressArray objectAtIndex:i] objectForKey:@"category_name"]; 
     NSLog(@"%@ and %@ and %f and %f of %@",lat,lon, lt,ln,name); 
                GMSMarker *marker = [[GMSMarker alloc] init]; 
               // marker.animated=YES; 
      marker.position = CLLocationCoordinate2DMake(lt,ln); 
      marker.title = name; 
      marker.map = _mapView; 

    }});}} 
    else 
    { 
     NSLog(@"Error: %@", error.localizedDescription); 
            } 
           }]; 
[task resume]; 
} 
+0

Refrain zu veröffentlichen Firma URL in Ihrem Code zu animieren. und Sie sollten debuggen, wenn Sie richtige Lat bekommen und vom Server loggen – Shubhank

+0

ich @Shubhank noch ich kann nicht herausfinden, das Problem. –

+0

Bitte kommen Sie zu [Chat] (http://chat.stackoverflow.com/rooms/26424/iosandroidchaosoverflow) – Shubhank

Antwort

1

aus dem Chat es wurde herausgefunden, dass Ihre Karte an einen anderen Ort initialisiert wurde eher dann an der Stelle, wo Sie waren Hinzufügen der Marker. Um es zu lösen diesen Code verwenden, um die Karte, um die Markierung Position

GMSCameraPosition *newCameraPosition = [GMSCameraPosition cameraWithTarget:cordinate zoom:10]; 
[self.mapView animateToCameraPosition:newCameraPosition]; 
+0

danke, es funktioniert @shubhank –

Verwandte Themen