ios - 谷歌地图上未显示注释或标记
<p><p>有两个文件 .h 和 .m 有完整的代码,请帮我找出问题,为什么标记没有出现。
我也安装了 pod 文件和 <code>googlemap sdk</code>。一切正常,但只是没有显示标记,我也在日志中打印了值,它们运行良好,但 map 上没有标记或注释。</p>
<p>.h 文件</p>
<pre><code>#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
</code></pre>
<p>.m 文件</p>
<pre><code>#import "ViewController.h"
#import "SimplestGoogleMapApp-Prefix.pch"
#import <GoogleMaps/GoogleMaps.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
;
self.mapView.myLocationEnabled=YES;
self.mapView.mapType=kGMSTypeNormal;
self.mapView.settings.compassButton=YES;
self.mapView.settings.myLocationButton=YES;
self.mapView.delegate=self;
;
}
-(void)addMarlerToMap{
NSURL *kAPIURL = ;
NSString *jsonString = @"data={some data}";
NSData *JSONData = ;
NSMutableURLRequest *request = ;
request.HTTPMethod = @"POST";
request.HTTPBody = JSONData;
NSURLSessionDataTask *task = [ 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 = ;
for(int i=0;i<=;i++){
self.view = _mapView;
NSString *lat = [ objectForKey:@"lat"];
NSString *lon = [ objectForKey:@"lng"];
double lt=;
double ln=;
NSString *name = [ objectForKey:@"category_name"];
NSLog(@"%@ and %@ and %f and %f of %@",lat,lon, lt,ln,name);
GMSMarker *marker = [ init];
// marker.animated=YES;
marker.position = CLLocationCoordinate2DMake(lt,ln);
marker.title = name;
marker.map = _mapView;
}});}}
else
{
NSLog(@"Error: %@", error.localizedDescription);
}
}];
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><blockquote>
<p>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</p>
</blockquote>
<pre><code>GMSCameraPosition *newCameraPosition = ;
;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 谷歌地图上未显示注释或标记,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37019674/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37019674/
</a>
</p>
页:
[1]