• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 谷歌地图上未显示注释或标记

[复制链接]
菜鸟教程小白 发表于 2022-12-13 16:12:12 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

有两个文件 .h 和 .m 有完整的代码,请帮我找出问题,为什么标记没有出现。 我也安装了 pod 文件和 googlemap sdk。一切正常,但只是没有显示标记,我也在日志中打印了值,它们运行良好,但 map 上没有标记或注释。

.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 = @"OST";
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];
 }



Best Answer-推荐答案


From the chat it was figured out that your map was initialised to a different location rather then the place where you were adding the markers. To solve it use this code to animate the map to the marker position

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

关于ios - 谷歌地图上未显示注释或标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37019674/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap