Google地图:地面覆盖图会随地图移动或调整大小

时间:2015-03-29 22:16:30

标签: android ios google-maps

我根据文档下载了最新的Google Maps SDK,并与我的项目集成。地图显示正常。我覆盖在谷歌地图上的地图调整大小或移动,即使我设置我想要锚定图像的坐标。如何停止并保持地图锚定?Displaced floor

以下是我的iOS代码,但它同时适用于Android和iOS。

ViewController.h

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

@interface ViewController : UIViewController <CLLocationManagerDelegate, GMSIndoorDisplayDelegate, GMSMapViewDelegate>

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@property int counter;

@property (nonatomic, strong) GMSMapView *mapView;
@property (nonatomic, strong) GMSMarker *myMarker;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, strong) CLLocationCoordinate2D location;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.295210
                                                            longitude:-124.032841
                                                                 zoom:10.5];
    self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    self.mapView.delegate = self;

    self.view = self.mapView;
    [self.mapView setMapType:kGMSTypeHybrid];

/* Location Manager stuff */
}

- (void) viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self stopSending];
}

- (void) viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self stopSending];
}

- (void) overlapMap {
    self.mapView.mapType = kGMSTypeNormal;
    CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(40.295048, -124.033110);
    CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(40.295385, -124.032801);
    GMSGroundOverlay *overlay = [self setGroundOverlayWithSouthWestCoordinate:southWest AndNorthEastCoordinate:northEast AndImage:[UIImage imageNamed:@"floorplan.png"]];

    overlay.map = self.mapView;
    [self.mapView animateToCameraPosition:[GMSCameraPosition
                                           cameraWithLatitude:40.295210
                                           longitude:-124.032951
                                           zoom:30]];
    [self.mapView setUserInteractionEnabled:true];
    [self showMarkers];
}

- (void) showMarkers {
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateMarkerDetails) userInfo:nil repeats:YES];
}

- (void) updateMarkerDetails {

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            CLLocationCoordinate2D location = [self getLocation];


            if (CLLocationCoordinate2DIsValid(location) {
                self.myMarker = [GMSMarker markerWithPosition:location];

                self.myMarker.map = self.mapView;
                self.osLocation.map = self.mapView;

            }

            [self.mapView setSelectedMarker:self.myMarker];

            /* some code with the marker title and subtitle*/    

            dispatch_async(dispatch_get_main_queue(), ^{
                [self.myMarker setPosition:location];
            });

        });
}

- (void) clearMap {
    self.myMarker.map = nil;
    self.osLocation.map = nil;
    [self.timer invalidate];
    self.timer = nil;
}

- (CLLocationCoordinate2D) getLocation {
    return self.location;
}

/* 
Location Manager related code 
Some other proprietary code
*/

@end

1 个答案:

答案 0 :(得分:0)

似乎有几种解决方案可供选择:

  1. 计算半径并获取地图屏幕的米数。因为地图背景覆盖宽度和高度值是米。使用米而不是缩放级别或其他任何东西
  2. 实施mMap.setOnCameraChangeListener
  3. 将自定义图片设置为标记图标,其大小将保持不变
  4. 详细信息:link