Flutter 颤振:如何获取屏幕中心点的位置坐标 我在我的颤动应用程序中使用谷歌地图,我想把一个指针放在屏幕中间,这样用户就可以很容易地通过移动地图来选择查找位置,并使屏幕中间的指针指向他们寻找的位置。 那么,我如何得到位于屏幕中部的坐标,与指针在
完全相同,可以使用<代码>屏幕坐标< /代码>:< /p>Flutter 颤振:如何获取屏幕中心点的位置坐标 我在我的颤动应用程序中使用谷歌地图,我想把一个指针放在屏幕中间,这样用户就可以很容易地通过移动地图来选择查找位置,并使屏幕中间的指针指向他们寻找的位置。 那么,我如何得到位于屏幕中部的坐标,与指针在,flutter,maps,coordinates,Flutter,Maps,Coordinates,完全相同,可以使用屏幕坐标< /代码>:< /p> import 'dart:async'; import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; 检查GoogleMapController官方文档ScreenCoordination要求(x,y)参数为实际像素数,因此请记住考虑devicePixelRatio。i、 e.实际像素数为width
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
检查
GoogleMapController
官方文档ScreenCoordination
要求(x,y)参数为实际像素数,因此请记住考虑devicePixelRatio
。i、 e.实际像素数为width*devicePixelRatioscreenWidth*=MediaQuery.of(context).devicePixelRatio;screenHeight*=MediaQuery.of(context).devicePixelRatio;
double screenWidth = MediaQuery.of(context).size.width *
MediaQuery.of(context).devicePixelRatio;
double screenHeight = MediaQuery.of(context).size.height *
MediaQuery.of(context).devicePixelRatio;
double middleX = screenWidth / 2;
double middleY = screenHeight / 2;
ScreenCoordinate screenCoordinate = ScreenCoordinate(x: middleX.round(), y: middleY.round());
LatLng middlePoint = await googleMapController.getLatLng(screenCoordinate);