react-native-google-maps-directions
react-native-google-maps-directions copied to clipboard
Trying to use custom latitude and longitude value from parameters
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 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
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.
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);
}