Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Directions using Address query #57

Closed
ben55j opened this issue Jan 11, 2021 · 8 comments
Closed

Show Directions using Address query #57

ben55j opened this issue Jan 11, 2021 · 8 comments

Comments

@ben55j
Copy link

ben55j commented Jan 11, 2021

Hello,

Is there a possibility to use the showDirections function using an address query ? If no, are you planning to do it?.

Thank you,
Benjamin

@DhavalRKansara
Copy link

@mattermoran I have the same requirement, Can you please provide an option to pass address(as string) or latitude-longitude for origin, destination, and waypoints.

Because with the long-lat it shows different address names in the google maps.

@mattermoran
Copy link
Owner

Hi @ben55j @DhavalRKansara
Sorry took me forever to answer. It's technically possible now since I added extraParams parameter on showMarker so you could override the q query param like so

map.showMarker(
    coords: Coords(0, 0),
    title: title,
    zoom: zoom,
    extraParams: {
      'q': '200 Union St, San Francisco, CA 94133', // here just use an address it will override latlong
    },
  );

Just tested on android seem to work. Haven't tried on ios but should be same

Let me know if that helps

@DhavalRKansara
Copy link

@mattermoran This will work in the case of ShowMarker, But How I can pass origin, destination and Waypoints address as extraparameters in showDirections method because we have only a single parameter over there?

Do we have to manage extraParams dictionary according to that with proper keys? If yes then what will be the keys for origin, destination and waypoints?

@mattermoran
Copy link
Owner

Should also work for showDirections.
This is what url builder looks like for google directions:

case MapType.google:
  return Utils.buildUrl(
    url: 'https://www.google.com/maps/dir/',
    queryParams: {
      'api': '1',
      'destination': '${destination.latitude},${destination.longitude}',
      'origin': Utils.nullOrValue(
        origin,
        '${origin?.latitude},${origin?.longitude}',
      ),
      'waypoints': waypoints
          ?.map((coords) => '${coords.latitude},${coords.longitude}')
          .join('|'),
      'travelmode': Utils.enumToString(directionsMode),
      ...(extraParams ?? {}),
    },
  );

As you can see the keys are origin, destination, and waypoints
You can try to override in extraParams and if see that works. Just make sure you separate waypoints with |

Ideally, the plugin should support the address even if it only works in google maps I'll try to get to it when have time.
For now, I hope the hack with extraParams work :)

@AleksandarSavic95
Copy link

Hello there! Thank you for developing this package! <3

I tested this "address without coordinates hack" on iOS and I can confirm that it works well for GoogleMaps app, but not for Apple Maps ("native" maps app for iPhones). To get the Apple Maps to open and show the address I wanted, I had to do this:

UrlLauncher.launchURL('https://maps.apple.com/?q=' + Uri.encodeQueryComponent(fullAddress));
// Full address full name + address from google maps api, like "Restaurant Royale Punjab,Restaurant Royale Punjab, Jarry Street West, Montreal, QC, Canada"

Note 1: before the map opens, I get an in-app browser which tries opening maps.apple.com
Note2: launchURL is just my wrapper method for the url_launcher package (code below). You can just import url_launcher package directly and use the if-else from the snippet below.

import 'package:url_launcher/url_launcher.dart';

class UrlLauncher {
  UrlLauncher._();

  static void launchURL(String url) async {
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }
}

Looking forward to having a showAddress method! 😊

@michael-woolsey
Copy link

I would really like to have the ability to use showMarker without having to supply the coords where they are the users current location, or showDirections where you can only use a q option without having to supply the coords.

My use case is, I need to query a location based off of the users current location. I would like to do this without having to supply the geolocation as that requires a permission I would rather not add, as I do not need it.

I'm using this hack for Apple and Google right now, but it's certainly not ideal.

Thank you for the great package!

@mleonhard
Copy link

I need this to work in Apple Maps.

Thank you @AleksandarSavic95 for the workaround.

url_launcher.launch(url) returns a future that does not complete in my app in Simulator. The workaround is to simply not await it.

When specifying q=, Google Maps ignores the title param. To open the maps page for a place, include the place name at the front of the query. Both Apple Maps and Google Maps will perform a fuzzy search and show the correct place page even if the address is incorrect.

final q = '$placeName, $streetAddress, $city';
if (map.mapType == MapType.apple) {
  final url = ('https://maps.apple.com/?q=' + Uri.encodeQueryComponent(q));
  if (!await url_launcher.canLaunch(url)) {
    throw 'cannot not launch url $url';
  }
  /* await */ url_launcher.launch(url);
} else {
  map.showMarker(
    coords: Coords(0, 0),
    title: meeting.placeName,
    extraParams: {'q': q},
  );
}

@mattermoran
Copy link
Owner

This feature is planned for v3 and anything related to this will be tracked in #114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants