问题描述
在我的应用程序中,我使用 GMSMapView
,并且我想更改跟踪模式。在iOS MapKit中,我可以将跟踪模式更改为 MKUserTrackingModeFollowWithHeading
,但不知道如何在 GMSMapView
。 $ b
在应用程序 Google Maps
中,它在第二次触摸 myLocationButton
。是否有可能?
要连续更改当前位置的相机,您需要将Google地图的GMSCamera更新为当前位置。您可以在位置管理器委托方法中执行此操作。
CLLocation * location;
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
//从didUpdateLocation获取当前的经度和纬度
location = [locations lastObject] ;
$ b - (void)locationManager:(CLLocationManager *)manager didUpdateHeading :( CLHeading *)newHeading
{
GMSCameraPosition * camera = [GMSCameraPosition cameraWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude zoom:10 bearing:newHeading.trueHeading viewingAngle:0];
//您可以将viewingAngle从0改为45
[self.mapForView animateToCameraPosition:camera];
}
如果您的委托没有被调用,请从我的答案此处一>
希望它有帮助。
In my app, I am using GMSMapView
, and I would like to change tracking mode. In iOS MapKit, I can change the tracking mode to MKUserTrackingModeFollowWithHeading
, but don't know how to change it in GMSMapView
.
In the app Google Maps
, it is working after second touch on myLocationButton
. Is it possible?
For continuously changing the camera with the current location, you will need to update the GMSCamera for google maps to current location. You can do it in Location Manager delegate method.
CLLocation *location;
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
//Get current latitude and longitude from didUpdateLocation
location = [locations lastObject];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude zoom:10 bearing:newHeading.trueHeading viewingAngle:0];
//You can change viewingAngle from 0 to 45
[self.mapForView animateToCameraPosition:camera];
}
In case your delegate is not getting called, take help from my answer here
Hope it helps.
这篇关于GMSMapView跟踪模式标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!