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.

Can't pass currentLocation to my initial cameraPosition in "map_view" #96

Closed

Description

@morad00

What I need:

  • Set the current location to the initial camerPosition in map_view
  • Set a draggable marker starts in the current location

What problem I faced:

  • My currentLocation always waiting and returns null
    currentLocation = await userLocation.getLocation;

My async method

Future _pickPlace() async {
    var getPresentLocation;
    try {
      getPresentLocation = await userLocation.getLocation;
      error = null;
    } on PlatformException catch (e) {
      if (e.code == 'PERMISSION_DENIED') {
        error = 'Permission denied';
      } else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
        error = 'Permission denied - please ask the user to enable it from the app settings';
      }
      getPresentLocation = null;
    }
    print('current location = ${getPresentLocation}');
  

map_view .show() method

mapView.show(
      MapOptions(
        showUserLocation: true,
        title: "Choose a place",
        initialCameraPosition: CameraPosition(
            locMapView.Location(getPresentLocation["latitude"],
                getPresentLocation['longitude']),
            15.0),
      ),
      toolbarActions: <ToolbarAction>[
        ToolbarAction("Close", 1),
      ]);

  mapView.onToolbarAction.listen((id) {
    if (id == 1) {
      print('1');
      mapView.dismiss();
    }
  });

  mapView.addMarker(new Marker(
    "1",
    "Pick up place!",
    getPresentLocation["latitude"],
    getPresentLocation['longitude'],
    draggable: true,
  ));

Any ideas ?

Activity

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