我在 Flutter 中有一個 json 檔案,其中包含列出的每個位置的 x、y 坐標。當我單擊 ListTile 時,我想轉到與 JSON 坐標匹配的 Google 地圖上的地址。在我的 JSON 檔案中,我有名為“location_x”和“location_y”的屬性,它們是特定位置的坐標。到目前為止,這是我的代碼:
void onTouch() {
print('Home Clicked');
Navigator.pop(context);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Farmers\' Market Finder'),
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: readJsonFile,
child: const Text('Nearby Markets'),
),
),
if (_farmersMarkets.isNotEmpty)
Expanded(
child: ListView.builder(
itemCount: _farmersMarkets.length,
itemBuilder: (BuildContext context, index) {
return Card(
margin: const EdgeInsets.all(15),
color: const Color.fromARGB(255, 243, 186, 54),
child: ListTile(
title: Text(_farmersMarkets[index]['listing_name']),
subtitle:
Text(_farmersMarkets[index]['location_address']),
onTap: onTouch,
),
uj5u.com熱心網友回復:
您可以使用maps_launcher打開帶有 lat 和 lng 的地圖。
例子 :
import 'package:maps_launcher/maps_launcher.dart';
MapsLauncher.launchQuery('1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA');
MapsLauncher.launchCoordinates(37.4220041, -122.0862462);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/506197.html
