如何显示用户当前位置在缩放视图加载iOS中吗? - How to Show User Current Location On Zoom When View Did Load in iOS?

- 此内容更新于:2015-12-13
主题:

我新手在iOS开发做一个瞪眼的地图支持应用程序显示用户当前位置,但当我按CurrentLocation按钮然后我显示用户当前位置,但我想告诉用户当前位置没有按钮按下我的意思是当我展示与变焦请帮我直接当前位置。像在我这里我写代码。和代码的请帮我显示当前位置没有当前位置按钮按下。请帮助我如何获取当前位置的地址在谷歌地图。谢谢。

原文:

I am newbie in iOS Development i make an Goggle map Supported app it Shows User Current Location but When i Press CurrentLocation Button on my GMSMapView then i show user Current Location but i want to Show User to Current Location WithOut Button Press i mean When viewDidLoad i Show Direct Current Location with Zoom Please Help me.

Here i Write a code like as in my .h File.

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

@interface MapViewController : UIViewController<GMSMapViewDelegate>
@property (nonatomic,retain) IBOutlet GMSMapView *mapView;
@end

And Code for .m File like as

- (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;
}

Please help me For Show Current location without Current location Button Press. And Please Help me How to Get Current Location Address in Google map.

thanks.

解决方案:
试一试:记住,可能如果位置还没有确定!您可以使用键值观察(KVO)确定当前位置当动画。
原文:

Try:

[self.mapView animateToLocation: self.mapView.myLocation.coordinate];

Keep in mind that myLocation might be nil if the location is not determined yet! You could use Key-Value Observing (KVO) to determine when to animate to current location.

-(void) viewDidLoad {
    [super viewDidLoad];
    [self.mapView addObserver:self forKeyPath:@"myLocation" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{

    if ([keyPath isEqualToString:@"myLocation"]) {
        // Animate map to current location (This will run every time user location updates! 
        [self.mapView animateToLocation: self.mapView.myLocation.coordinate];
        // You can remove self from observing 'myLocation' to only animate once
        [self.mapView removeObserver:self forKeyPath:@"myLocation"];
    }
}
网友:@thnksamrin但不是在模拟工作。我想从经度和纬度得到地址如何可能?

(原文:@thnks amrin but it is not working in simulated. and i want to get address from latitude and Longitude how it is Possible?)

网友:这里我想直接放大我的位置是不设置缩放直接我的位置就像当我在模拟机控件设置位置到孟买。那就只显示在孟买孟买不是一个完美的位置。请给我解决方案。

(原文:Here i want to Zoom DIrect to my Location It is Not Set Zoom to Direct my Location like as when i was Set Location to Mumbai in my simulater .then it is Only Show Mumbai Not A perfect Location in mumbai.Please give me solution for it.)

网友:您可以使用方法。所以设置

(原文:You can use the - (void) animateToZoom: (float) zoom method. so set the [self.mapView animateToZoom: zoomFloat];)

网友:你应该阅读文档:developers.google.com/maps/documentation/ios/reference/?

(原文:You should really read the documentation: developers.google.com/maps/documentation/ios/reference/…)