如何在flutter或dart中缩放给定的2个纬度和经度的Google地图



现在工作正确,但有人帮助纠正。

缩放因子使用以下方法。我有疑问,请检查一下。

输出视图

现在函数工作正常-尽管我对它有疑问。如果您看到任何问题,请告诉我。

zoom(LatLngBounds value,padding){
var maxY = value.southwest.longitude,minY = value.northeast.longitude,deltaX = value.southwest.latitude,centerX=0.0;
var ry1 = math.log((math.sin(toRadian(minY))+1)/math.cos(toRadian(minY))) ;
var ry2 = math.log((math.sin(toRadian(maxY))+1)/math.cos(toRadian(maxY))) ;
var ryc = (ry1+ry2)/2.0;
var centerY = toDegree(math.atan(Trath.sinh(ryc)));
var resolutionHorizontal = deltaX/Get.width;
var vy0 = math.log(math.tan(math.pi*(0.25+centerY/360.0)));
var vy1 = math.log(math.tan(math.pi*(0.25+maxY/360.0)));
var viewHeightHalf = Get.width/2.0;
var zoomFactorPowered = viewHeightHalf/ (40.7436654315252*(vy1 - vy0));
var resolutionVertical = 360.0/(zoomFactorPowered*256);
var resolution = math.max(resolutionVertical, resolutionHorizontal)*padding;
var zoom = math.log(360/(resolution*256))/math.log(2);
print("!====E${zoom}");
var lon =  centerX;
var lat = centerY;
return zoom;
}

部件

GoogleMap(
onMapCreated: (GoogleMapController controller) {
if(bounds!=null){
var dist =  Geolocator.distanceBetween(bounds!.northeast.latitude, bounds!.northeast.latitude, bounds!.southwest.latitude, bounds!.southwest.latitude);
String round = "${dist.round()}";
var nzf;
if(round.length==5){
nzf = 40;
}else if(round.length==4){
nzf = 52;
}else if(round.length==3){
nzf = 85;
}else if(round.length==2){
nzf = 95;
}
var zf = nzf/(zoom(bounds!,600)*-1);
print("=Zoom Factor==${round} ${dist} == ${zf}");
//_controller.complete()
controller?.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target:center!,
zoom: zf,
),
),
);
// controller.animateCamera(u2).then((void v){
//   check(u2,controller);
// });
}
},
onCameraMove: _onCameraMove,
initialCameraPosition: CameraPosition(target: center!,zoom: 14
),
mapType: MapType.satellite,
tiltGesturesEnabled: true,
buildingsEnabled: true,
indoorViewEnabled: true,
mapToolbarEnabled: true,
myLocationButtonEnabled: true,
rotateGesturesEnabled: true,
myLocationEnabled: true,
scrollGesturesEnabled: true,
//trafficEnabled: true,
zoomControlsEnabled: true,
zoomGesturesEnabled: true,
compassEnabled: true,
polylines: Set<Polyline>.of(polylines.values), //polylines
) 

最新更新