hi there和早上好,什么是最好的方式来放置一个标记在屏幕上,并移动谷歌Map到该标记,以获得用户所需的位置比如送餐应用和拼车应用,有没有人有主意?
dddzy1tm1#
应该是这样的:
import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; class MyMap extends StatefulWidget { const MyMap({Key? key}) : super(key: key); @override State<MyMap> createState() => _MyMapState(); } class _MyMapState extends State<MyMap> { CameraPosition initialCameraPosition = const CameraPosition( target: LatLng(37.789682, -122.3901086), zoom: 14, ); final Set<Marker> _markers = {}; LatLng _lastMapPosition = const LatLng(37.789682, -122.3901086); GoogleMapController? googleMapController; @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: true, body: Stack( children: [ GoogleMap( onMapCreated: (GoogleMapController controller) { googleMapController = controller; }, markers: _markers, mapType: MapType.normal, initialCameraPosition: initialCameraPosition, compassEnabled: true, mapToolbarEnabled: true, onCameraMove: _onCameraMove, ), Center( child: Container( child: const Icon(Icons.circle_outlined, color: Colors.blue, size: 25), ), ), ], ), ); } void _onCameraMove(CameraPosition p) { // this is the position of the marker on the top of you Map // TODO : change print to what you went to do with the new location. print("New Loctaion ${p.target.longitude}, ${p.target.latitude}"); _lastMapPosition = p.target; } }
**注意:**记住要将Google Map API添加到您的项目中,才能使其工作。
Google Map API
1条答案
按热度按时间dddzy1tm1#
应该是这样的:
**注意:**记住要将
Google Map API
添加到您的项目中,才能使其工作。