react-native-google-maps-directions icon indicating copy to clipboard operation
react-native-google-maps-directions copied to clipboard

Unsupported link when using more than one waypoint

Open armin23615 opened this issue 5 years ago • 5 comments

RN version: 0.60 Package version: 2.1.1

This is the data I supplay to getDirections method: const data = { source: { latitude: Number(checkpoints[0].address.lat), longitude: Number(checkpoints[0].address.lng), }, destination: { latitude: Number(checkpoints[numOfCheckpoints - 1].address.lat), longitude: Number(checkpoints[numOfCheckpoints - 1].address.lng), }, params: [ { key: 'travelmode', value: 'driving', // may be "walking", "bicycling" or "transit" as well }, { key: 'dir_action', value: 'navigate', // this instantly initializes navigation using the given travel mode }, ], waypoints: [ { latitude: 39.810355, longitude: -86.135126 }, { latitude: 40.810355, longitude: -86.135126 }, ], }

I'm getting error inside maps: Google maps can't open this link. When I use only one waypoint it works fine though.

I have my url in log: 'https://www.google.com/maps/dir/?api=1&travelmode=driving&dir_action=navigate&destination=39.881652%2C-83.057822&origin=41.925685%2C-88.122813&waypoints=39.810355,-86.135126|40.810355,-86.135126'

armin23615 avatar Jan 16 '20 11:01 armin23615

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.66. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

issue-label-bot[bot] avatar Jan 16 '20 11:01 issue-label-bot[bot]

In index.js under react-native-google-maps-directions directory in node_modules if you change the method const getParams = (params = []) => { return params .map(({ key, value }) => { const encodedKey = encodeURIComponent(key) const encodedValue = encodeURIComponent(value) return${encodedKey}=${encodedValue}}) .join('&') } to const getParams = (params = []) => { return params .map(({ key, value }) => { // const encodedKey = encodeURIComponent(key) // const encodedValue = encodeURIComponent(value) return${key}=${value}}) .join('&') } it will work

kristianmilev1 avatar Feb 12 '20 14:02 kristianmilev1

@kristianmilev1 I don't really see the difference in your code..

Areskyb avatar Jun 02 '20 18:06 Areskyb

There is an issue with multiple waypoints. Regarding the docs https://developers.google.com/maps/documentation/urls/get-started#parameters_1, characters like | inside waypoints should be converted to %2C. But if we follow to @kristianmilev1 suggestion, all works good for google app and browser on android and ios.

I guess when we use Linking.openURL(url) with no escaped characters like , or | this method do it for us internally. Correct me please if I'm wrong.

So just copy code

// old
const getParams = (params = []) => {
  return params
    .map(({ key, value }) => {
      const encodedKey = encodeURIComponent(key)
      const encodedValue = encodeURIComponent(value)
      return `${encodedKey}=${encodedValue}`
    })
    .join('&')
}

to

// new
const getParams = (params = []) => {
  return params
    .map(({ key, value }) => {
      return `${key}=${value}`;
    })
    .join('&');
};

alexeyvax avatar Aug 03 '20 14:08 alexeyvax

There is an issue with multiple waypoints. Regarding the docs https://developers.google.com/maps/documentation/urls/get-started#parameters_1, characters like | inside waypoints should be converted to %2C. But if we follow to @kristianmilev1 suggestion, all works good for google app and browser on android and ios.

I guess when we use Linking.openURL(url) with no escaped characters like , or | this method do it for us internally. Correct me please if I'm wrong.

So just copy code

// old
const getParams = (params = []) => {
  return params
    .map(({ key, value }) => {
      const encodedKey = encodeURIComponent(key)
      const encodedValue = encodeURIComponent(value)
      return `${encodedKey}=${encodedValue}`
    })
    .join('&')
}

to

// new
const getParams = (params = []) => {
  return params
    .map(({ key, value }) => {
      return `${key}=${value}`;
    })
    .join('&');
};

I tried this @alexeyvax, and multiple waypoints are working for me now 💪

AndriesJacobus avatar Oct 26 '20 19:10 AndriesJacobus