我有一个手势检测器,其中包含一个GoogleMap小部件,当点击打开谷歌Map应用程序(我也在浏览器中尝试),这在Android模拟器和物理设备上都可以工作,但在iOS模拟器或物理设备上不行。Map仍然显示以及但是,你可以与它互动(放大和缩小),但点击什么也不做。我已经正确设置了所有内容,并且对API没有任何限制,是什么原因导致了这一点?
原始程式码:
//Google Maps
final Completer<GoogleMapController> _controller =
Completer<GoogleMapController>();
static const CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(51.917405387278585, -8.397318089507758),
zoom: 17,
);
static const CameraPosition _initialCameraPosition = CameraPosition(
bearing: 192.8334901395799,
target: LatLng(51.917405387278585, -8.397318089507758),
tilt: 59.440717697143555,
zoom: 19.151926040649414);
//Launch google maps app
void launchGoogleMaps() async {
// Define the latitude and longitude of the desired location
final double latitude = 51.917405387278585;
final double longitude = -8.397318089507758;
final Uri googleMapsUrl = Uri.parse(
'https://www.google.com/maps/search/?api=1&query=$latitude,$longitude');
_launch(googleMapsUrl);
}
Future<void> _launch(Uri url) async {
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
throw 'Could not launch Google Maps';
}
}
//**Attempt to open on browser failed on both platforms
Future<void> openGoogleMapsInBrowser() async {
final double latitude = 51.917405387278585;
final double longitude = -8.397318089507758;
final Uri googleMapsUrl =
Uri.parse('https://www.google.com/maps?q=$latitude,$longitude');
if (await canLaunchUrl(googleMapsUrl)) {
await launchUrl(googleMapsUrl);
} else {
throw 'Could not launch Google Maps in the web browser.';
}
}
Padding(
padding: const EdgeInsets.all(22.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: GestureDetector(
onTap: launchGoogleMaps,
child: SizedBox(
height: 300,
child: GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: _kGooglePlex,
onMapCreated:
(GoogleMapController controller) {
_controller.complete(controller);
// Add the marker to the map when it's created
setState(() {
_markers.add(
Marker(
markerId: MarkerId('your_marker_id'),
position: LatLng(51.917405387278585,
-8.397318089507758),
icon: BitmapDescriptor
.defaultMarkerWithHue(
BitmapDescriptor.hueRed),
// Add other properties as needed
),
);
});
},
markers:
_markers, // Set the markers on the map
),
),
),
),
),
我已经确保我有所有正确的导入和一切都设置完美,是什么原因导致它在IOS上无法点击?
1条答案
按热度按时间rjee0c151#
要在iOS上使用url_launcher,请打开ios/Runner/Info.plist文件并按如下所示修改它。参考:https://dev-yakuza.posstree.com/en/flutter/url_launcher/external_link/
然后: