Skip to main content
se añadieron 252 caracteres en el cuerpo
Origen Enlace
gisela
  • 605
  • 2
  • 6
  • 16

el widget con el que es llamada GoogleMaps es un InkWell

return InkWell(
      onTap: () {
        Route route = MaterialPageRoute(builder: (context) => GoogleMaps(x,y));
        Navigator.push(context, route);
      },

el widget con el que es llamada GoogleMaps es un InkWell

return InkWell(
      onTap: () {
        Route route = MaterialPageRoute(builder: (context) => GoogleMaps(x,y));
        Navigator.push(context, route);
      },
se eliminaron 216 caracteres en el cuerpo
Origen Enlace
gisela
  • 605
  • 2
  • 6
  • 16
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:provider/provider.dart';
import 'DirectionProvider.dart';
import 'package:geolocator/geolocator.dart';

class GoogleMaps extends StatefulWidget {
  final String x, y;
  GoogleMaps(this.x, this.y);
  final LatLng fromPoint = LatLng(-37.020125, -62.409388); 

  static ChangeNotifierProvider init(double x, double y) =>  ChangeNotifierProvider(
      create: (_) => new DirectionProvider(),
  );

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

class _GoogleMapsState extends State<GoogleMaps> {
  Position _currentPosition;
  LatLng toPoint; 

  void initState() {
    _getCurrentLocation();
    var x2 = double.parse(widget.x);
    var y2 = double.parse(widget.y);
    toPoint = new LatLng(x2, y2);
    super.initState();
  }

  GoogleMapController _mapController;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Google Maps'),
      ),
      body: ChangeNotifierProvider(
          create: (_) => new DirectionProvider(),
          child: Builder(
              builder: (context) => Consumer<DirectionProvider>(
                    builder: (BuildContext context_, DirectionProvider api,
                        Widget child__) {
                      return GoogleMap(
                        initialCameraPosition: CameraPosition(
                          target: widget.fromPoint,
                          zoom: 12,
                        ),
                        markers: _createMarkers(),
                        polylines: api.currentRoute,
                        onMapCreated: _onMapCreated,
                        myLocationEnabled: true,
                        myLocationButtonEnabled: true,
                      );
                    },
                  ))),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.zoom_out_map),
        onPressed: _centerView,
      ),
    );
  }

  Set<Marker> _createMarkers() {
    var tmp = Set<Marker>();

    tmp.add(Marker(
      markerId: MarkerId("FromPoint"),
      position: widget.fromPoint,
      infoWindow: InfoWindow(title: "estoy aca"),
    ));

    tmp.add(Marker(
      markerId: MarkerId("toPoint"),
      position: toPoint,
      infoWindow: InfoWindow(title: "llegada"),
    ));
    return tmp;
  }

  void _onMapCreated(GoogleMapController controller) {
    _mapController = controller;

    _centerView();
  }

  _centerView() async {
    var api = Provider.of<DirectionProvider>(context);

    await _mapController.getVisibleRegion();

    print("buscando direcciones");
    await api.findDirections(widget.fromPoint, toPoint);

    var left = min(
        widget.fromPoint.latitude, toPoint.latitude); //SE CALCULA COORDENADAS.
    var right = max(widget.fromPoint.latitude, toPoint.latitude);
    var top = max(widget.fromPoint.longitude, toPoint.longitude);
    var bottom = min(widget.fromPoint.longitude, toPoint.longitude);

    api.currentRoute.first.points.forEach((point) {
      left = min(left, point.latitude);
      right = max(right, point.latitude);
      top = max(top, point.longitude);
      bottom = min(bottom, point.longitude);
    });

    var bounds = LatLngBounds(
      southwest: LatLng(left, bottom),
      northeast: LatLng(right, top),
    );
    var cameraUpdate = CameraUpdate.newLatLngBounds(bounds, 50);
    _mapController.animateCamera(cameraUpdate);
  } 


  _getCurrentLocation() {
    var geolocator = Geolocator();
    var locationOptions = LocationOptions(accuracy: LocationAccuracy.high, distanceFilter: 10);

    StreamSubscription<Position> positionStream = geolocator.getPositionStream(locationOptions).listen((Position position) {
          print(position == null ? 'Unknown' : position.latitude.toString() + ', ' + position.longitude.toString());
        });
  }
}
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:provider/provider.dart';
import 'DirectionProvider.dart';
import 'package:geolocator/geolocator.dart';

class GoogleMaps extends StatefulWidget {
  final String x, y;
  GoogleMaps(this.x, this.y);
  final LatLng fromPoint = LatLng(-37.020125, -62.409388);
  @override
  _GoogleMapsState createState() => _GoogleMapsState();
}

class _GoogleMapsState extends State<GoogleMaps> {
  Position _currentPosition;
  LatLng toPoint;
  void initState() {
    _getCurrentLocation();
    var x2 = double.parse(widget.x);
    var y2 = double.parse(widget.y);
    toPoint = new LatLng(x2, y2);
    super.initState();
  }

  GoogleMapController _mapController;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Google Maps'),
      ),
      body: ChangeNotifierProvider(
          create: (_) => new DirectionProvider(),
          child: Builder(
              builder: (context) => Consumer<DirectionProvider>(
                    builder: (BuildContext context, DirectionProvider api,
                        Widget child) {
                      return GoogleMap(
                        initialCameraPosition: CameraPosition(
                          target: widget.fromPoint,
                          zoom: 12,
                        ),
                        markers: _createMarkers(),
                        polylines: api.currentRoute,
                        onMapCreated: _onMapCreated,
                        myLocationEnabled: true,
                        myLocationButtonEnabled: true,
                      );
                    },
                  ))),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.zoom_out_map),
        onPressed: _centerView,
      ),
    );
  }

  Set<Marker> _createMarkers() {
    var tmp = Set<Marker>();

    tmp.add(Marker(
      markerId: MarkerId("FromPoint"),
      position: widget.fromPoint,
      infoWindow: InfoWindow(title: "estoy aca"),
    ));

    tmp.add(Marker(
      markerId: MarkerId("toPoint"),
      position: toPoint,
      infoWindow: InfoWindow(title: "llegada"),
    ));
    return tmp;
  }

  void _onMapCreated(GoogleMapController controller) {
    _mapController = controller;

    _centerView();
  }

  _centerView() async {
    var api = Provider.of<DirectionProvider>(context);

    await _mapController.getVisibleRegion();

    print("buscando direcciones");
    await api.findDirections(widget.fromPoint, toPoint);

    var left = min(
        widget.fromPoint.latitude, toPoint.latitude); //SE CALCULA COORDENADAS.
    var right = max(widget.fromPoint.latitude, toPoint.latitude);
    var top = max(widget.fromPoint.longitude, toPoint.longitude);
    var bottom = min(widget.fromPoint.longitude, toPoint.longitude);

    api.currentRoute.first.points.forEach((point) {
      left = min(left, point.latitude);
      right = max(right, point.latitude);
      top = max(top, point.longitude);
      bottom = min(bottom, point.longitude);
    });

    var bounds = LatLngBounds(
      southwest: LatLng(left, bottom),
      northeast: LatLng(right, top),
    );
    var cameraUpdate = CameraUpdate.newLatLngBounds(bounds, 50);
    _mapController.animateCamera(cameraUpdate);
  }

  _getCurrentLocation() {
    var geolocator = Geolocator();
    var locationOptions = LocationOptions(accuracy: LocationAccuracy.high, distanceFilter: 10);

    StreamSubscription<Position> positionStream = geolocator.getPositionStream(locationOptions).listen((Position position) {
          print(position == null ? 'Unknown' : position.latitude.toString() + ', ' + position.longitude.toString());
        });
  }
}
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:provider/provider.dart';
import 'DirectionProvider.dart';
import 'package:geolocator/geolocator.dart';

class GoogleMaps extends StatefulWidget {
  final String x, y;
  GoogleMaps(this.x, this.y);
  final LatLng fromPoint = LatLng(-37.020125, -62.409388); 

  static ChangeNotifierProvider init(double x, double y) =>  ChangeNotifierProvider(
      create: (_) => new DirectionProvider(),
  );

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

class _GoogleMapsState extends State<GoogleMaps> {
  Position _currentPosition;
  LatLng toPoint; 

  void initState() {
    _getCurrentLocation();
    var x2 = double.parse(widget.x);
    var y2 = double.parse(widget.y);
    toPoint = new LatLng(x2, y2);
    super.initState();
  }

  GoogleMapController _mapController;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Google Maps'),
      ),
      body:  Consumer<DirectionProvider>(
        builder: (_,api,__) {
          return GoogleMap(
            initialCameraPosition: CameraPosition(
              target: widget.fromPoint,
              zoom: 12,
            ),
            markers: _createMarkers(),
            polylines: api.currentRoute,
            onMapCreated: _onMapCreated,
            myLocationEnabled: true,
            myLocationButtonEnabled: true,
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.zoom_out_map),
        onPressed: _centerView,
      ),
    );
  }

  Set<Marker> _createMarkers() {
    var tmp = Set<Marker>();

    tmp.add(Marker(
      markerId: MarkerId("FromPoint"),
      position: widget.fromPoint,
      infoWindow: InfoWindow(title: "estoy aca"),
    ));

    tmp.add(Marker(
      markerId: MarkerId("toPoint"),
      position: toPoint,
      infoWindow: InfoWindow(title: "llegada"),
    ));
    return tmp;
  }

  void _onMapCreated(GoogleMapController controller) {
    _mapController = controller;

    _centerView();
  }

  _centerView() async {
    var api = Provider.of<DirectionProvider>(context);

    await _mapController.getVisibleRegion();

    print("buscando direcciones");
    await api.findDirections(widget.fromPoint, toPoint);

    var left = min(
        widget.fromPoint.latitude, toPoint.latitude); //SE CALCULA COORDENADAS.
    var right = max(widget.fromPoint.latitude, toPoint.latitude);
    var top = max(widget.fromPoint.longitude, toPoint.longitude);
    var bottom = min(widget.fromPoint.longitude, toPoint.longitude);

    api.currentRoute.first.points.forEach((point) {
      left = min(left, point.latitude);
      right = max(right, point.latitude);
      top = max(top, point.longitude);
      bottom = min(bottom, point.longitude);
    });

    var bounds = LatLngBounds(
      southwest: LatLng(left, bottom),
      northeast: LatLng(right, top),
    );
    var cameraUpdate = CameraUpdate.newLatLngBounds(bounds, 50);
    _mapController.animateCamera(cameraUpdate);
  } 


  _getCurrentLocation() {
    var geolocator = Geolocator();
    var locationOptions = LocationOptions(accuracy: LocationAccuracy.high, distanceFilter: 10);

    StreamSubscription<Position> positionStream = geolocator.getPositionStream(locationOptions).listen((Position position) {
          print(position == null ? 'Unknown' : position.latitude.toString() + ', ' + position.longitude.toString());
        });
  }
}
Se actualizo el codigo.
Origen Enlace
gisela
  • 605
  • 2
  • 6
  • 16

como andan? estoy trabajando con Google Maps, en esta oportunidad, me encuentro con el siguiente error: (Provider)

>import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:provider/provider.dart';
import 'DirectionProvider.dart';
import 'package:geolocator/geolocator.dart';

class GoogleMaps extends StatefulWidget {
  final String x, y;
  GoogleMaps(this.x, this.y);
  final LatLng fromPoint = LatLng(-37.020125, -62.409388);
  @override
  _GoogleMapsState createState() => _GoogleMapsState();
}

class _GoogleMapsState extends State<GoogleMaps> {
  Position _currentPosition;
  LatLng toPoint;
  void initState() {
    _getCurrentLocation();
    var x2 = double.parse(widget.x);
    var y2 = double.parse(widget.y);
    toPoint = new LatLng(x2, y2);
    super.initState();
  }

  GoogleMapController _mapController;
  @override
  Widget build(BuildContext context) {
>     return Scaffold(
>       appBar: AppBar(
>         title: Text('Google Maps'),
>       ),
>       body: ChangeNotifierProvider(
>           create: (_) => new DirectionProvider(),
>           child: Consumer<DirectionProvider>Builder(
>              builder: (context) => Consumer<DirectionProvider>(
>                    builder: (BuildContext context, DirectionProvider api,
                        Widget child) {
>                      return GoogleMap(
>                        initialCameraPosition: CameraPosition(
>                          target: widget.fromPoint,
>                          zoom: 12,
>                        ),
>                        markers: _createMarkers(),
>                        polylines: api.currentRoute,
>                        onMapCreated: _onMapCreated,
>                        myLocationEnabled: true,
>                        myLocationButtonEnabled: true,
>                      );
>                    },
>                  ))),
>       floatingActionButton: FloatingActionButton(
>         child: Icon(Icons.zoom_out_map),
>         onPressed: _centerView,
>      ),
    );
  }

  Set<Marker> _createMarkers() {
    var tmp = Set<Marker>();

    tmp.add(Marker(
      markerId: MarkerId("FromPoint"),
      position: widget.fromPoint,
      infoWindow: InfoWindow(title: "estoy aca"),
>    ));

    tmp.add(Marker(
      markerId: MarkerId("toPoint"),
      position: toPoint,
      infoWindow: InfoWindow(title: "llegada"),
    ));
    return tmp;
  }

  void _onMapCreated(GoogleMapController controller) {
    _mapController = controller;

    _centerView();
  }

  _centerView() async {
    var api = Provider.of<DirectionProvider>(context);

    await _mapController.getVisibleRegion();

    print("buscando direcciones");
    await api.findDirections(widget.fromPoint, toPoint);

    var left = min(
        widget.fromPoint.latitude, toPoint.latitude); //SE CALCULA COORDENADAS.
    var right = max(widget.fromPoint.latitude, toPoint.latitude);
    var top = max(widget.fromPoint.longitude, toPoint.longitude);
    var bottom = min(widget.fromPoint.longitude, toPoint.longitude);

    api.currentRoute.first.points.forEach((point) {
      left = min(left, point.latitude);
      right = max(right, point.latitude);
      top = max(top, point.longitude);
      bottom = min(bottom, point.longitude);
    });

    var bounds = LatLngBounds(
      southwest: LatLng(left, bottom),
      northeast: LatLng(right, top),
    );
    var cameraUpdate = CameraUpdate.newLatLngBounds(bounds, 50);
    _mapController.animateCamera(cameraUpdate);
  }

  _getCurrentLocation() {
    var geolocator = Geolocator();
    var locationOptions = LocationOptions(accuracy: LocationAccuracy.high, distanceFilter: 10);

    StreamSubscription<Position> positionStream = geolocator.getPositionStream(locationOptions).listen((Position position) {
          print(position == null ? 'Unknown' : position.latitude.toString() + ', ' + position.longitude.toString());
        });
  }
}

No puedo encontrar, sinceramente el error. Muchas Muchas gracias de antemano. Ya Ejecute Flutter Clean. También esta la clase DirectionProvider, pero en ésta, simplemente esta al api key y se calcula cual es el mejor camino para llegar a destino.

(se actualizo)

estoy trabajando con Google Maps, en esta oportunidad, me encuentro con el siguiente error:

>  Widget build(BuildContext context) {
>     return Scaffold(
>       appBar: AppBar(
>         title: Text('Google Maps'),
>       ),
>       body:ChangeNotifierProvider(
>           create: (_) => new DirectionProvider(),
>           child: Consumer<DirectionProvider>(
>             builder:
>                 (BuildContext context, DirectionProvider api, Widget child) {
>               return GoogleMap(
>                 initialCameraPosition: CameraPosition(
>                   target: widget.fromPoint,
>                   zoom: 12,
>                 ),
>                 markers: _createMarkers(),
>                 polylines: api.currentRoute,
>                 onMapCreated: _onMapCreated,
>                 myLocationEnabled: true,
>                 myLocationButtonEnabled: true,
>               );
>             },
>           )),
>       floatingActionButton: FloatingActionButton(
>         child: Icon(Icons.zoom_out_map),
>         onPressed: _centerView,
>       ),
>     );   }

No puedo encontrar, sinceramente el error. Muchas gracias de antemano.

como andan? estoy trabajando con Google Maps, en esta oportunidad, me encuentro con el siguiente error: (Provider)

import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:provider/provider.dart';
import 'DirectionProvider.dart';
import 'package:geolocator/geolocator.dart';

class GoogleMaps extends StatefulWidget {
  final String x, y;
  GoogleMaps(this.x, this.y);
  final LatLng fromPoint = LatLng(-37.020125, -62.409388);
  @override
  _GoogleMapsState createState() => _GoogleMapsState();
}

class _GoogleMapsState extends State<GoogleMaps> {
  Position _currentPosition;
  LatLng toPoint;
  void initState() {
    _getCurrentLocation();
    var x2 = double.parse(widget.x);
    var y2 = double.parse(widget.y);
    toPoint = new LatLng(x2, y2);
    super.initState();
  }

  GoogleMapController _mapController;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Google Maps'),
      ),
      body: ChangeNotifierProvider(
          create: (_) => new DirectionProvider(),
          child: Builder(
              builder: (context) => Consumer<DirectionProvider>(
                    builder: (BuildContext context, DirectionProvider api,
                        Widget child) {
                      return GoogleMap(
                        initialCameraPosition: CameraPosition(
                          target: widget.fromPoint,
                          zoom: 12,
                        ),
                        markers: _createMarkers(),
                        polylines: api.currentRoute,
                        onMapCreated: _onMapCreated,
                        myLocationEnabled: true,
                        myLocationButtonEnabled: true,
                      );
                    },
                  ))),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.zoom_out_map),
        onPressed: _centerView,
      ),
    );
  }

  Set<Marker> _createMarkers() {
    var tmp = Set<Marker>();

    tmp.add(Marker(
      markerId: MarkerId("FromPoint"),
      position: widget.fromPoint,
      infoWindow: InfoWindow(title: "estoy aca"),
    ));

    tmp.add(Marker(
      markerId: MarkerId("toPoint"),
      position: toPoint,
      infoWindow: InfoWindow(title: "llegada"),
    ));
    return tmp;
  }

  void _onMapCreated(GoogleMapController controller) {
    _mapController = controller;

    _centerView();
  }

  _centerView() async {
    var api = Provider.of<DirectionProvider>(context);

    await _mapController.getVisibleRegion();

    print("buscando direcciones");
    await api.findDirections(widget.fromPoint, toPoint);

    var left = min(
        widget.fromPoint.latitude, toPoint.latitude); //SE CALCULA COORDENADAS.
    var right = max(widget.fromPoint.latitude, toPoint.latitude);
    var top = max(widget.fromPoint.longitude, toPoint.longitude);
    var bottom = min(widget.fromPoint.longitude, toPoint.longitude);

    api.currentRoute.first.points.forEach((point) {
      left = min(left, point.latitude);
      right = max(right, point.latitude);
      top = max(top, point.longitude);
      bottom = min(bottom, point.longitude);
    });

    var bounds = LatLngBounds(
      southwest: LatLng(left, bottom),
      northeast: LatLng(right, top),
    );
    var cameraUpdate = CameraUpdate.newLatLngBounds(bounds, 50);
    _mapController.animateCamera(cameraUpdate);
  }

  _getCurrentLocation() {
    var geolocator = Geolocator();
    var locationOptions = LocationOptions(accuracy: LocationAccuracy.high, distanceFilter: 10);

    StreamSubscription<Position> positionStream = geolocator.getPositionStream(locationOptions).listen((Position position) {
          print(position == null ? 'Unknown' : position.latitude.toString() + ', ' + position.longitude.toString());
        });
  }
}

No puedo encontrar, sinceramente el error. Muchas gracias de antemano. Ya Ejecute Flutter Clean. También esta la clase DirectionProvider, pero en ésta, simplemente esta al api key y se calcula cual es el mejor camino para llegar a destino.

(se actualizo)

Origen Enlace
gisela
  • 605
  • 2
  • 6
  • 16
Loading