微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我想将路线折线从我在颤动地图中的当前位置添加到特定位置

如何解决我想将路线折线从我在颤动地图中的当前位置添加到特定位置

在我的 Flutter 项目中,我实现了显示我当前位置的谷歌地图。我想添加到特定位置(即折线)的路线[现在我想将该特定位置保留为硬编码值]。

我该怎么做?另外,Direction API 是收费的还是免费的??

这是我用于访问我当前位置的谷歌地图代码

import 'dart:async';
import 'dart:math';

import 'package:Flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_Flutter/google_maps_Flutter.dart';
import 'package:thehelpdesk/widgets/appbar.dart';
class GoogleMapPage extends StatefulWidget {
  @override
  _GoogleMapPageState createState() => _GoogleMapPageState();
}

class _GoogleMapPageState extends State<GoogleMapPage> {

  Completer<GoogleMapController> _controllerGoogleMap = Completer();
  GoogleMapController newGoogleMapController ;

  GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
  Position currentPosition ;
  var geoLocator = Geolocator();

  void locatePosition() async{
    Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
    currentPosition = position;

    LatLng latLngPosition = LatLng(position.latitude,position.longitude);

    CameraPosition cameraPosition = new CameraPosition(target: latLngPosition,zoom: 14);
    newGoogleMapController.animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
  }

  static final CameraPosition _cameraPosition = CameraPosition(
    target: LatLng(19.8100241,85.8177131),zoom: 14.4746);

  @override
final List<Marker> markers = [];

  addMarker(coordinate) {
    int id = Random().nextInt(100);
    setState(() {
      markers.add(Marker(position: coordinate,markerId: MarkerId(id.toString())));
    });
  }
Widget build(BuildContext context) {
    return Scaffold(
      key: scaffoldKey,appBar: aapBarSection('Google Map',Colors.blueAccent[700],context),body: GoogleMap(
        initialCameraPosition: _cameraPosition,mapType: MapType.normal,myLocationButtonEnabled: true,myLocationEnabled: true,zoomGesturesEnabled: true,onMapCreated: (GoogleMapController controller) {
_controllerGoogleMap.complete(controller);
          newGoogleMapController = controller;

          locatePosition();
        },markers: markers.toSet(),onTap: (coordinate) {
          newGoogleMapController.animateCamera(CameraUpdate.newLatLng(coordinate));
          addMarker(coordinate);
        },),);
  }
}

请帮帮我! 提前致谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。