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

Trying to use custom latitude and longitude value from parameters

Open Pradnyana28 opened this issue 7 years ago • 3 comments

I'm trying to set latitude and longitude destination from a value that I had. But it return blank when open up in google maps.

  handleGetDirections = (latitude, longitude) => {
     const data = {
     source: {
       latitude: -8.627666,
       longitude: 115.239225
     },
     destination: {
       latitude: latitude,
       longitude: longitude
     },
     params: [
       {
         key: "dirflg",
         value: "c"
       }
     ]
  };

  getDirections(data);
}

So how I can set a custom latitude and longitude value ? Thank you.

Pradnyana28 avatar Nov 03 '17 15:11 Pradnyana28

@Pradnyana28 could you please check that the latitude and longitude values are passed correctly to the handleGetDirections method. If so, could you provide the example input in order for me to replicate

tiaanduplessis avatar Nov 03 '17 15:11 tiaanduplessis

Yes, it appears in the log console correctly.

And this is how I assigned the value

onPress={this.handleGetDirections.bind(this, row.location.latitude, row.location.longitude)}

I don't know why it doesn't work, also I have tried others method but still doesn't work.

Pradnyana28 avatar Nov 03 '17 15:11 Pradnyana28

I might have run into a similar issue. Google Maps was able to detect source, but not the lat/lng parameters of destination when passing them in as arguments. I realized the values needed to be type number before sending them into getDirections(data). They had become strings. This ended up working for me:

  handleGetDirections = (latitude, longitude) => {
    const data = {
      destination: { 
        latitude: Number(latitude),
        longitude: Number(longitude),
      },
      params: [
        {
          key: 'dirflg',
          value: 'd',
        }
      ]
    };
    getDirections(data);
  }

acoulon99 avatar Nov 12 '17 00:11 acoulon99