Created
March 21, 2021 00:33
-
-
Save carlosmoretti/c47bdc0ec3de4ba6ed318592a61992f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:async'; | |
| import 'package:flutter/cupertino.dart'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:google_maps_flutter/google_maps_flutter.dart'; | |
| import 'package:location/location.dart'; | |
| class MapWidget extends StatefulWidget { | |
| _MapWidget createState() => _MapWidget(); | |
| } | |
| class _MapWidget extends State<MapWidget> { | |
| LatLng _initialcameraposition = LatLng(20.5937, 78.9629); | |
| GoogleMapController _controller; | |
| Location _location = Location(); | |
| void _onMapCreated(GoogleMapController _cntlr) | |
| { | |
| _controller = _cntlr; | |
| _location.onLocationChanged.listen((l) { | |
| _controller.animateCamera( | |
| CameraUpdate.newCameraPosition( | |
| CameraPosition(target: LatLng(l.latitude, l.longitude),zoom: 15), | |
| ), | |
| ); | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Container( | |
| height: MediaQuery.of(context).size.height, | |
| width: MediaQuery.of(context).size.width, | |
| child: Stack( | |
| children: [ | |
| GoogleMap( | |
| initialCameraPosition: CameraPosition(target: _initialcameraposition), | |
| mapType: MapType.normal, | |
| onMapCreated: _onMapCreated, | |
| myLocationEnabled: true, | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment