gpt4 book ai didi

ios - 适用于 iOS 的 Google Maps SDK 上的平滑滚动

转载 作者:技术小花猫 更新时间:2023-10-29 10:39:45 25 4
gpt4 key购买 nike

所以我想根据纬度和经度值将 Google map 可滚动区域限制为 map 上的某个矩形。为此,我编写了以下代码:

-(void) viewDidLoad{
startLat = 43.331635f;
startLong = -74.472913f;
endLat = 43.329106f;
endLong = -74.470589f;
float cameraPosLat = (startLat + endLat) / 2.0f;
float cameraPosLong = (startLong + endLong) / 2.0f;

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:cameraPosLat
longitude:cameraPosLong
zoom:18];
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.mapType = kGMSTypeSatellite;
mapView.delegate = self;
mapView.myLocationEnabled = YES;
[mapView setMinZoom:18 maxZoom:mapView.maxZoom];
self.view = mapView;
marker.map = mapView;
}

-(void) mapView:(GMSMapView *)delegateMapView didChangeCameraPosition:(GMSCameraPosition *)position{
if(delegateMapView.camera.target.latitude > startLat){
[delegateMapView moveCamera:[GMSCameraUpdate setTarget:CLLocationCoordinate2DMake(startLat, delegateMapView.camera.target.longitude)]];
}
if(delegateMapView.camera.target.latitude < endLat){
[delegateMapView moveCamera:[GMSCameraUpdate setTarget:CLLocationCoordinate2DMake(endLat, delegateMapView.camera.target.longitude)]];
}
if(delegateMapView.camera.target.longitude < startLong){
[delegateMapView moveCamera:[GMSCameraUpdate setTarget:CLLocationCoordinate2DMake(delegateMapView.camera.target.latitude, startLong)]];
}
if(delegateMapView.camera.target.longitude > endLong){
[delegateMapView moveCamera:[GMSCameraUpdate setTarget:CLLocationCoordinate2DMake(delegateMapView.camera.target.latitude, endLong)]];
}
}

这很好用,它将 map 停在我希望它停在的点上,但是我注意到的一件事是,在可接受的边界的边缘,滚动非常跳跃,而不是平滑。我想知道是否有任何方法可以确保 map 保持在指定范围内,同时还能保持边缘的平滑滚动。

如有任何帮助,我们将不胜感激,谢谢!

最佳答案

试试这个:

-(void) mapView:(GMSMapView *)delegateMapView didChangeCameraPosition:(GMSCameraPosition *)position{
if(delegateMapView.camera.target.latitude > startLat){
[delegateMapView animateToCameraPosition:[GMSCameraPosition
cameraWithLatitude:startLat
longitude:delegateMapView.camera.target.longitude
zoom:delegateMapView.camera.zoom]];
}
if(delegateMapView.camera.target.latitude < endLat){
[delegateMapView animateToCameraPosition:[GMSCameraPosition
cameraWithLatitude:endLat
longitude:delegateMapView.camera.target.longitude
zoom:delegateMapView.camera.zoom]];
}
if(delegateMapView.camera.target.longitude < startLong){
[delegateMapView animateToCameraPosition:[GMSCameraPosition
cameraWithLatitude:delegateMapView.camera.target.latitude
longitude:startLong
zoom:delegateMapView.camera.zoom]];
}
if(delegateMapView.camera.target.longitude > endLong){
[delegateMapView animateToCameraPosition:[GMSCameraPosition
cameraWithLatitude:delegateMapView.camera.target.latitude
longitude:endLong
zoom:delegateMapView.camera.zoom]];
}
}

关于ios - 适用于 iOS 的 Google Maps SDK 上的平滑滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30326168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com