完全なコードを持つ2つのファイル.hと.mがあります。なぜマーカーが表示されないのかを問題解決に役立ててください。 ポッドファイルとgooglemap sdk
もインストールしました。すべてが正常に機能していますが、マーカーが表示されないだけでなく、ログにも値が表示されます。うまく機能していますが、マップ上にマーカーや注釈はありません。注釈またはマーカーがGoogleマップに表示されていません
.hファイル
#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ファイル
#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];
}
リフレインマーカー 位置にマップをアニメーション化するために、このコードを使用します。サーバーから適切なlatとログを取得している場合はデバッグする必要があります。 – Shubhank
私は@Shubhankをやっていますが、問題はまだ分かりません。 –
[チャット](http://chat.stackoverflow.com/rooms/26424/iosandroidchaosoverflow)に来てください – Shubhank