am calling a google geocoding api via java, and getting wrong answer ! for example if i run the query below from browser i get the location but if i run it using a rest client i get zero result !!! is there anything to solve this issue ?
https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=18+RUE+DE+NIEDECK++++39255+OTTERSWILLER®ion=FR&key=AI.....
this is the answer from Google Chrome or Mozilla :
{
"results" : [
{
"address_components" : [
{
"long_name" : "18",
"short_name" : "18",
"types" : [ "street_number" ]
},
{
"long_name" : "Rue du Nideck",
"short_name" : "Rue du Nideck",
"types" : [ "route" ]
},
{
"long_name" : "Otterswiller",
"short_name" : "Otterswiller",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Bas-Rhin",
"short_name" : "Bas-Rhin",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Grand Est",
"short_name" : "Grand Est",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "France",
"short_name" : "FR",
"types" : [ "country", "political" ]
},
{
"long_name" : "67700",
"short_name" : "67700",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "18 Rue du Nideck, 67700 Otterswiller, France",
"geometry" : {
"location" : {
"lat" : 48.7237784,
"lng" : 7.363452799999998
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 48.7251273802915,
"lng" : 7.364801780291501
},
"southwest" : {
"lat" : 48.7224294197085,
"lng" : 7.362103819708497
}
}
},
"partial_match" : true,
"place_id" : "ChIJXwysfE2nlkcRjwlaKN_gmrE",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
and this is the answer for the same address when i use a rest client :
{
"results" : [],
"status" : "ZERO_RESULTS"
}
This is my code , and i am using apache http client version 4.5
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
as for the code here it is :
String f = "https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=18+RUE+DE+NIEDECK++++39255+OTTERSWILLER®ion=FR&key=googlekey";
// executing the request
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(f);
HttpResponse response = client.execute(request);
String responseBody = EntityUtils.toString(response.getEntity());
System.out.println(responseBody);
String f = "https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=18+RUE+DE+NIEDECK++++39255+OTTERSWILLER®ion=FR&key=AI"; HttpGet httpGet = new HttpGet(f); HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(f); HttpResponse response = client.execute(request); String responseBody = EntityUtils.toString(response.getEntity()); System.out.println(responseBody);