Flutter: Google Maps - pegando a localização atual.

17/07/2019

6

eu tentei de varias formas de pegar minha localização porem não conseguir.

Alguém poderia me ajudar

--------------------------------------------------------------------------------------------------------------------
tentei dessa forma e outras, porem sem exceto
GoogleMap(
myLocationEnabled: true,
myLocationButtonEnabled: true,
zoomGesturesEnabled: true,



mapType: MapType.normal,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);

},
),
--------------------------------------------------------------------------------------------------------------------

codigo completo

import 'dart:convert';

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

import 'dart:async';


class TelaPrincipal extends StatefulWidget {
TelaPrincipal({@required this.bloc}); // não a necessidade
final TelaPrincipal bloc; // não a necessidade


@override
_TelaPrincipal createState() => _TelaPrincipal();
}



class _TelaPrincipal extends State<TelaPrincipal> {

bool mapToggle = false;

// var currentLocation;
var sitioActual;
var currentBearing;

@override
State<TelaPrincipal> createState() => _TelaPrincipal();
Completer<GoogleMapController> _controller = Completer();
GoogleMapController mapController;


static final CameraPosition _kGooglePlex = CameraPosition(
target: LatLng(-12.9702118, -39.2635447),
zoom: 20.4746,
);



static final CameraPosition _kLake = CameraPosition(
// bearing: 192.8334901395799,

// target: LatLng(currentLocation.latitude, currentLocation.longitude),
target: LatLng(-12.9702118, -39.2635447),
tilt: 59.440717697143555,
zoom: 20.151926040649414);



Future<void> _goToPosition1() async {
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(_kLake));
}

Widget button(Function function, IconData icon) {
return FloatingActionButton(
onPressed: function,
materialTapTargetSize: MaterialTapTargetSize.padded,
backgroundColor: Colors.black12,
child: Icon(icon, size: 36.0,),
);
}

@override
Widget build(BuildContext context) {
return new Scaffold(
body: Stack(
children: <Widget>[
GoogleMap(
myLocationEnabled: true,
myLocationButtonEnabled: true,
zoomGesturesEnabled: true,



mapType: MapType.normal,
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);

},
),

Padding(
padding: EdgeInsets.all(16.0),

child: Align(

alignment: Alignment.bottomRight,


child: new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.end, //responsavel pela ordem/alinhamento de onde começa o container
children: <Widget>[
button(_goToPosition1, Icons.location_searching),
],
),
),
),
)
], ),
);
}



}
Responder
×
+1 DevUP
Acesso diário, +1 DevUP
Parabéns, você está investindo na sua carreira