Tildes in API Google Maps android studio

1

I am using the Google Maps API in an application. I use Google's autocomplete and the streets come out with accents, but when I pass them to the url to get the distance, it does not return anything.

This is the code:

str= "Calle Doctor José Montilla Bono, Jaén";
str2= "Gran Via, Calle Gran Vía de Colón, Granada";

String urlString = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + str + "&destinations=" + str2 + "&mode=driving&key=0000000000000000000";

Generate the query url: link

but the application fails me and if I open that url I get this:

  

{
  "destination_addresses": [],
  "origin_addresses": [],
  "rows": [],
  "status": "INVALID_REQUEST"
  }

Does anyone know why it can be?

Thank you very much Greetings

    
asked by jejefufu 09.04.2017 в 11:53
source

1 answer

0

The accents do not actually cause the problem, the error is actually specified in the response, it is an "invalid request" because the parameter departure_time is missing:

  

{destination_addresses: [],   error_message: "Invalid request. Missing the 'departure_time' parameter.",   origin_addresses: [],   rows: [],   status: "INVALID_REQUEST"}

Remember that:

  

The arrival_time parameter (the arrival time) or the departure_time parameter must be specified at any time when   request transit directions.

For example if we add the parameters to your original url, we have:

link

the answer:

{
destination_addresses: [
"Calle Gran Vía de Colón, Granada, España"
],
origin_addresses: [
"Calle Dr. José Montilla Bono, 23009 Jaén, España"
],
rows: [
{
elements: [
{
distance: {
text: "92,4 km",
value: 92432
},
duration: {
text: "1h 1 min",
value: 3645
},
status: "OK"
}
]
}
],
status: "OK"
}

It is very important that you get a valid KEY API, since the one you use ( key=0000000000 ) is not valid to use in production.

    
answered by 16.05.2017 в 01:50