Flutter-Google地图,不显示我的位置 [英] Flutter - google map, does not show my location

查看:232
本文介绍了Flutter-Google地图,不显示我的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎一切都写得正确,但我不明白为什么它不能在地图上显示我的位置.

It seems to have written everything correctly but I can not understand why it does not show my location on the map.

为什么不显示我的位置?

Why is it not showing my location?

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class MyMap extends StatefulWidget {
  @override
  MyMapState createState() => MyMapState();
}

class MyMapState extends State<MyMap> {
  GoogleMapController mapController;

  final LatLng _center = const LatLng(50.006406, 36.236484);

  void _onMapCreated(GoogleMapController controller) {
    mapController = controller;
    mapController.addMarker(
      MarkerOptions(
        position: LatLng(50.006406, 36.236484),
        infoWindowText: InfoWindowText('My Location', 'Office'),
        icon: BitmapDescriptor.defaultMarker,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Map'),
          backgroundColor: Colors.green[700],
        ),
        body: GoogleMap(
          onMapCreated: _onMapCreated,
          options: GoogleMapOptions(
            scrollGesturesEnabled: true,
            tiltGesturesEnabled: true,
            rotateGesturesEnabled: true,
            myLocationEnabled: true,
            compassEnabled: true,
            cameraPosition: CameraPosition(
              target: _center,
              zoom: 11.0,
            ),
          ),
        ),
      );
  }
}

推荐答案

如果您想在地图上查看您的当前位置,并启用右下方的 FAB 功能将您带到那里,请确保您在GoogleMap窗口小部件上将属性 myLocationEnabled 设置为 true .

If you want to see your current location on the map, and enable the lower right FAB functionality that takes you there, make sure you have the property myLocationEnabled set to true on your GoogleMap Widget.

      [...]
      body: GoogleMap(
          myLocationEnabled: true,
          [...]
      )

这篇关于Flutter-Google地图,不显示我的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆