获取Google地图中图标位置的经度和纬度

时间:2018-12-08 12:16:19

标签: google-maps dart flutter

在我的Flutter应用中。我正在使用google_maps_plugin。链接为https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter。 我想在拖动地图后将标记固定在地图中心而不移动图标。我通过使用stack成功完成了操作。但是我的问题是如何获取放置在stack中的图标的经度和纬度。 我希望它像http://jsfiddle.net/UuDA6/

代码如下所示。

    class MyApp extends StatelessWidget {

    MyApp();

    @override
    Widget build(BuildContext context) {
        return new MaterialApp(
        title: 'Title',
        theme: new ThemeData(
            primarySwatch: Colors.blue,
        ),
        home: new AppPage(title: 'Augr'),
        );
    }
    }

    class AppState extends InheritedWidget {
    const AppState({
        Key key,
        this.mode,
        Widget child,
    }) : assert(mode != null),
            assert(child != null),
            super(key: key, child: child);

    final Geocoding mode;

    static AppState of(BuildContext context) {
        return context.inheritFromWidgetOfExactType(AppState);
    }

    @override
    bool updateShouldNotify(AppState old) => mode != old.mode;
    }


    class AppPage extends StatefulWidget{
    AppPage() : super(key: key);

    @override
    _AppPageState createState() => new _AppPageState();
    }

    class _AppPagePageState extends State<MyApp> {
        _AppPagePageState();

    List<Address> results = [];
    String address;

    String googleMapsApiKey = 'APIKEY';
    GoogleMapController mapController;
    Position position;


        @override
    Widget build(BuildContext context){

        return new Scaffold(
            appBar: null,
            body: Padding(
                padding: EdgeInsets.only(top: 25.0),
                child:Column(
                children: <Widget>[
                    SizedBox(
                width: 200,
                height: 300,
                child: Stack(
                    children: <Widget>[
                    GoogleMap(
                    onMapCreated: _onMapCreated,
                ),
                InfoView()

                    ],
                ),
                ),],
                )
            ),
        );
    }

        void initState() {
            super.initState();   
        }

    void _onMapCreated(GoogleMapController controller) {
        setState(() {
        mapController = controller;
            mapController.animateCamera(CameraUpdate.newCameraPosition(
                    CameraPosition(
                    bearing: 270.0,
                    target: LatLng(lattitude, longitude),
                    tilt: 30.0,
                    zoom: 17.0,
                    ),
                ));
        });
    }
    }

    class InfoView extends StatelessWidget {
    const InfoView({
        Key key,
        })  : super(key: key);

            @override
    Widget build(BuildContext context) {
    return new Align(
            alignment: Alignment.center,
            child: new Icon(Icons.person_pin_circle, size: 40.0),  //This the icon showing in google map .

        );
    }
    }

infoView()被定义为在Google地图中显示重叠的图标。我想获取地图上图标位置的纬度和经度。 如果有任何想法,请分享。

0 个答案:

没有答案