【发布时间】:2022-01-05 11:11:46
【问题描述】:
在地图内选择一个地点后,我需要返回经度和纬度,所以我点击地图中的某个位置,它会返回经纬度信息,我可以启动地图,添加地点,但我只是无法选择地点并使用该信息进行回调,我找到了 googlemaps 的解决方案,但不是 flutter_map,非常感谢!!
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart' as latlng;
import 'package:flutter_map_tappable_polyline/flutter_map_tappable_polyline.dart';
class MapScreen extends StatefulWidget {
@override
_MapScreenState createState() => _MapScreenState();
}
class _MapScreenState extends State<MapScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Your Map'),
),
body: FlutterMap(
options: new MapOptions(
center: latlng.LatLng(-23.5732052, -46.6331934),
zoom: 18.0,
plugins: [
TappablePolylineMapPlugin(),
],
),
layers: [
TileLayerOptions(
urlTemplate: "https://api.mapbox.com/styles/v1/dxxx/ckwii7q6bxxrauou3d/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoiZGVtaWFuMjAyMSIsImEiOiJjxxxxxxxxxxxxxxxxxxxaWs1In0.2x2m7ka-KZwzBR5XXgYkXQ",
subdomains: ['a', 'b', 'c'],
additionalOptions: {
'accessToken':'pk.eyJ1IjoiZGVxxxxxxxxxxxxxxxxxxxxxxxxxxcHgxNXZoMnB1dGVvOWViaWs1In0.2x2m7ka-KZwzBR5XXgYkXQ',
'id': 'mapbox.mapbox-streets-v8',
},
attributionBuilder: (_) {
return Text("© OpenStreetMap contributors");
},
),
TappablePolylineLayerOptions(
// Will only render visible polylines, increasing performance
polylineCulling: true,
polylines: [
TaggedPolyline(
points: [latlng.LatLng(-22.5732052, -47.6331934), latlng.LatLng(-22.5732052, -47.6331934)],
tag: "My Polyline", // An optional tag to distinguish polylines in callback
// ...all other Polyline options
),
],
onTap: (polylines, tapPosition) => print('Tapped: ' +
polylines.map((polyline) => polyline.tag).join(',') +
' at ' +
tapPosition.globalPosition.toString()),
onMiss: (tapPosition) {
print('No polyline was tapped at position ' +
tapPosition.globalPosition.toString());
}
),
MarkerLayerOptions(
markers: [
Marker(
width: 40.0,
height: 40.0,
point: latlng.LatLng(-23.5732052, -46.6331934),
builder: (ctx) =>
Container(
child: FlutterLogo(),
),
),
],
),
],
),
);
}
}
【问题讨论】:
标签: android flutter flutter-dependencies