You need to sign in to do that
Don't have an account?
Google Maps API and 400 error
Hello, I'm having troubles trying to get data from google maps api, specifically distance matrix service.
The problem is that every time i send the request via salesforce i got a 400 error, BUT if I take the url of the endpoint from the logs and paste it in a browser the json is returned regularly:
Here is the code that I'm using: Am I missing something? Thank you in advance.
public String getJsonResults( String address1, String address2) { HttpRequest req = new HttpRequest(); Http http = new Http(); HttpRequest request = new HttpRequest(); String url = 'https://maps.googleapis.com/maps/api/distancematrix/json' + '?key=......' + '&origins=' + address1 + '&destinations=' + address2 + '&mode=driving' + '&sensor=false' + '&language=en' + '&units=imperial'; System.debug('url: ' + url); request.setEndpoint(url); request.setMethod('GET'); HttpResponse response = http.send(request);
that's what i get from system.debug when I check for the request:
System.HttpRequest[Endpoint=https://maps.googleapis.com/maps/api/distancematrix/json?key=......&origins=Via Celano,Avezzano&destinations=Via Roma,Aquila&mode=driving&sensor=false&language=en&units=imperial, Method=GET]
If i paste this string in a browser, it works.
Already added the endpoint "https://maps.googleapis.com" to remote sites, what should I do? Thanks again
I hope you find the above solution helpful. If it does mark as best answer to help others too.
Thanks,
Ramesh D
All Answers
I hope you find the above solution helpful. If it does mark as best answer to help others too.
Thanks,
Ramesh D
Thank you to all, I solved the problem with:
Many Thanks!!