Skip to content
This repository was archived by the owner on Jun 25, 2019. It is now read-only.
This repository was archived by the owner on Jun 25, 2019. It is now read-only.

Set current position as initial camera position? #63

Open

Description

@enyceedanny

Is there a simple way to set the current location for the initial position? When I use onLocationUpdated to set the updated position, it takes quite some time to update.

Activity

  1. matthewtsmith commented on Jun 15, 2018

    @matthewtsmith
    Member

    You could get the location first using something like: https://pub.dartlang.org/packages/location
    then pass that in when you call the showMap.

  2. enyceedanny commented on Jun 15, 2018

    @enyceedanny
    Author

    Hi thanks for the response.

    I've actually been trying that but can't seem to get it to work. Would you be able to provide me a bit more insight? New to flutter/dart. Thanks.

  3. jeffersonatsafe commented on Sep 13, 2018

    @jeffersonatsafe

    @enyceedanny

    here's how to do that.

    import 'package:location/location.dart' as location_services;
    
    Location _getStartingLocation() async {
      var location = location_services.Location();
      Map<String, double> _currentLocation;
        _currentLocation = await location.getLocation();
      return Location(_currentLocation["latitude"], _currentLocation["longitude"]);
    }
    
    void showMap() async {
        Location startingLocation = await _getStartingLocation();
        mapView.show(
            MapOptions(
              mapViewType: MapViewType.normal,
              showUserLocation: true,
              showMyLocationButton: true,
              initialCameraPosition: CameraPosition(startingLocation, 15.0),
              hideToolbar: false,
            ),
            toolbarActions: [ToolbarAction("Done", 1)]);
    }
    

    do note that there is a class name clash for Location, so you'd have to alias one of the package names.

  4. nicosalazar commented on Mar 21, 2019

    @nicosalazar

    @jeffersonatsafe i try use your code but i have the error in Location . Undefined class. can you help me ?

    do note that there is a class name clash for Location, so you'd have to alias one of the package names.???

  5. jeffersonatsafe commented on Mar 21, 2019

    @jeffersonatsafe

    @nicosalazar
    I've stopped using this plugin, since this plugin is also being abandoned.
    Google is working on an official Google Maps plugin. I suggest you use that one instead.
    Did you specify the other location plugin in your pubspec ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions