Google Geocoding and Autocomplete do not return the same number of results
For the same address entered by the user in the address input, the google Autocomplete API on the front-end (with javacript) returns a single result and thus a single choice for the user.
Whereas the Geocoder API on the back-end (PHP) returns two different results.
I have a back-end validation that gets the address entered by the user thanks to Autocomplete and checks this address with geocoder. If I have no results with the geocoder or more than one result (which is my case, since I get 2 results with the geocoder), I throw an exception.
This is an issue for me because my validation with the geocoder should be able to rely on the Autocomplete.
Please find below my extra explanation
Explanation:
I have a form on my website, where the user enters his address in an address input. This input uses the google Autocomplete API with javascript as follow.
var addressAutocompleteGoogleMaps = new google.maps.places.Autocomplete($myInputJqueryElement[0], {
componentRestrictions: {country: 'fr'},
types: ['geocode']
});
addressAutocompleteGoogleMaps.addListener('place_changed', function() {
var addressAutocompleteSelectedAddress = $myInputJqueryElement.val();
var autocompletionFormattedAddress = addressAutocompleteGoogleMaps.getPlace().formatted_address;
$myInputJqueryElement.val(autocompletionFormattedAddress);
// After having changed my form value to the formatted_address, I submit the form.
});
Now if the user enters the following address
21bis Rue Claude Bernard, 75005 Paris, France
(as you can see there is a space missing between the 21
and the bis
in the address), well on the front end-side, google Autocomplete seems to recognize this address and gives the user a single unique choice. As you can see below:
if I perform a console.log(addressAutocompleteGoogleMaps.getPlace());
, I can see a single result in my console, with the following attributes:
place_id: "ChIJzX6RiOtx5kcRCaog3ti3QTs"
formatted_address: "21bis Rue Claude Bernard, 75005 Paris, France"
geometry: {location: _.P, viewport: _.Q}
But in my back-end, I use the geocoder service of Google and do not tolerate more than one result from the API.
If I use the same address as the formatted_address
of the Autocomplete result on the front-end, which is 21bis Rue Claude Bernard, 75005 Paris, France
, and I submit it to the geocoder API on my back-end with to this URL
https://maps.googleapis.com/maps/api/geocode/json?key=myKey&language=fr®ion=fr&address=21bis+Rue+Claude+Bernard%2C+75005+Paris%2C+France
(as you can see in the URL parameters, there is no space between 21
and bis
because the submitted address by my user, based on the choice of Google Autocomplete does not contain a space either)
I get the following results from the geocoder:
As you can see I get two results with the geocoder from the address 21bis Rue Claude Bernard, 75005 Paris, France
.
But I only get one result with the Autocomplete.
Event the place_ids are not the same. With the autocomplete API, the place_id is ChIJzX6RiOtx5kcRCaog3ti3QT
. But with the geocode API, I get two other place_ids, which are ChIJVeIPVu9x5kcRPHRX59oID5M
and ChIJG9djYOxx5kcR1JtnnCReAxU
.
WHAT I WOULD LIKE
Why does the Google Geocoder not return the same results as the Google Autocomplete? How can I solve my problem?
I want:
- either my Autocomplete to return the same 2 results as my geocoder
- either my geocoder to return a single result, the same as the Autocomplete
(ps: And by the way, I tried typing the same address on the online geocoder of Google on https://developers.google.com/maps/documentation/geocoding/intro and I also get a single address as you can see below. So how come my back-end usage of the geocoding API still return 2 results??)
google-maps google-maps-api-3 autocomplete google-places-api google-geocoder
add a comment |
For the same address entered by the user in the address input, the google Autocomplete API on the front-end (with javacript) returns a single result and thus a single choice for the user.
Whereas the Geocoder API on the back-end (PHP) returns two different results.
I have a back-end validation that gets the address entered by the user thanks to Autocomplete and checks this address with geocoder. If I have no results with the geocoder or more than one result (which is my case, since I get 2 results with the geocoder), I throw an exception.
This is an issue for me because my validation with the geocoder should be able to rely on the Autocomplete.
Please find below my extra explanation
Explanation:
I have a form on my website, where the user enters his address in an address input. This input uses the google Autocomplete API with javascript as follow.
var addressAutocompleteGoogleMaps = new google.maps.places.Autocomplete($myInputJqueryElement[0], {
componentRestrictions: {country: 'fr'},
types: ['geocode']
});
addressAutocompleteGoogleMaps.addListener('place_changed', function() {
var addressAutocompleteSelectedAddress = $myInputJqueryElement.val();
var autocompletionFormattedAddress = addressAutocompleteGoogleMaps.getPlace().formatted_address;
$myInputJqueryElement.val(autocompletionFormattedAddress);
// After having changed my form value to the formatted_address, I submit the form.
});
Now if the user enters the following address
21bis Rue Claude Bernard, 75005 Paris, France
(as you can see there is a space missing between the 21
and the bis
in the address), well on the front end-side, google Autocomplete seems to recognize this address and gives the user a single unique choice. As you can see below:
if I perform a console.log(addressAutocompleteGoogleMaps.getPlace());
, I can see a single result in my console, with the following attributes:
place_id: "ChIJzX6RiOtx5kcRCaog3ti3QTs"
formatted_address: "21bis Rue Claude Bernard, 75005 Paris, France"
geometry: {location: _.P, viewport: _.Q}
But in my back-end, I use the geocoder service of Google and do not tolerate more than one result from the API.
If I use the same address as the formatted_address
of the Autocomplete result on the front-end, which is 21bis Rue Claude Bernard, 75005 Paris, France
, and I submit it to the geocoder API on my back-end with to this URL
https://maps.googleapis.com/maps/api/geocode/json?key=myKey&language=fr®ion=fr&address=21bis+Rue+Claude+Bernard%2C+75005+Paris%2C+France
(as you can see in the URL parameters, there is no space between 21
and bis
because the submitted address by my user, based on the choice of Google Autocomplete does not contain a space either)
I get the following results from the geocoder:
As you can see I get two results with the geocoder from the address 21bis Rue Claude Bernard, 75005 Paris, France
.
But I only get one result with the Autocomplete.
Event the place_ids are not the same. With the autocomplete API, the place_id is ChIJzX6RiOtx5kcRCaog3ti3QT
. But with the geocode API, I get two other place_ids, which are ChIJVeIPVu9x5kcRPHRX59oID5M
and ChIJG9djYOxx5kcR1JtnnCReAxU
.
WHAT I WOULD LIKE
Why does the Google Geocoder not return the same results as the Google Autocomplete? How can I solve my problem?
I want:
- either my Autocomplete to return the same 2 results as my geocoder
- either my geocoder to return a single result, the same as the Autocomplete
(ps: And by the way, I tried typing the same address on the online geocoder of Google on https://developers.google.com/maps/documentation/geocoding/intro and I also get a single address as you can see below. So how come my back-end usage of the geocoding API still return 2 results??)
google-maps google-maps-api-3 autocomplete google-places-api google-geocoder
3
Autocomplete and the geocoder are two different services, with different purposes. One uses the Places API, the other doesn't (necessarily). There is no reason they should behave the way you are expecting.
– geocodezip
Nov 23 '18 at 2:47
1) Each place ID can refer to only one place, but a single place can have more than one place ID. This is explained here. 2) Why do you need that extra validation and why do you do it with the geocoder?
– MrUpsidown
Nov 23 '18 at 9:13
add a comment |
For the same address entered by the user in the address input, the google Autocomplete API on the front-end (with javacript) returns a single result and thus a single choice for the user.
Whereas the Geocoder API on the back-end (PHP) returns two different results.
I have a back-end validation that gets the address entered by the user thanks to Autocomplete and checks this address with geocoder. If I have no results with the geocoder or more than one result (which is my case, since I get 2 results with the geocoder), I throw an exception.
This is an issue for me because my validation with the geocoder should be able to rely on the Autocomplete.
Please find below my extra explanation
Explanation:
I have a form on my website, where the user enters his address in an address input. This input uses the google Autocomplete API with javascript as follow.
var addressAutocompleteGoogleMaps = new google.maps.places.Autocomplete($myInputJqueryElement[0], {
componentRestrictions: {country: 'fr'},
types: ['geocode']
});
addressAutocompleteGoogleMaps.addListener('place_changed', function() {
var addressAutocompleteSelectedAddress = $myInputJqueryElement.val();
var autocompletionFormattedAddress = addressAutocompleteGoogleMaps.getPlace().formatted_address;
$myInputJqueryElement.val(autocompletionFormattedAddress);
// After having changed my form value to the formatted_address, I submit the form.
});
Now if the user enters the following address
21bis Rue Claude Bernard, 75005 Paris, France
(as you can see there is a space missing between the 21
and the bis
in the address), well on the front end-side, google Autocomplete seems to recognize this address and gives the user a single unique choice. As you can see below:
if I perform a console.log(addressAutocompleteGoogleMaps.getPlace());
, I can see a single result in my console, with the following attributes:
place_id: "ChIJzX6RiOtx5kcRCaog3ti3QTs"
formatted_address: "21bis Rue Claude Bernard, 75005 Paris, France"
geometry: {location: _.P, viewport: _.Q}
But in my back-end, I use the geocoder service of Google and do not tolerate more than one result from the API.
If I use the same address as the formatted_address
of the Autocomplete result on the front-end, which is 21bis Rue Claude Bernard, 75005 Paris, France
, and I submit it to the geocoder API on my back-end with to this URL
https://maps.googleapis.com/maps/api/geocode/json?key=myKey&language=fr®ion=fr&address=21bis+Rue+Claude+Bernard%2C+75005+Paris%2C+France
(as you can see in the URL parameters, there is no space between 21
and bis
because the submitted address by my user, based on the choice of Google Autocomplete does not contain a space either)
I get the following results from the geocoder:
As you can see I get two results with the geocoder from the address 21bis Rue Claude Bernard, 75005 Paris, France
.
But I only get one result with the Autocomplete.
Event the place_ids are not the same. With the autocomplete API, the place_id is ChIJzX6RiOtx5kcRCaog3ti3QT
. But with the geocode API, I get two other place_ids, which are ChIJVeIPVu9x5kcRPHRX59oID5M
and ChIJG9djYOxx5kcR1JtnnCReAxU
.
WHAT I WOULD LIKE
Why does the Google Geocoder not return the same results as the Google Autocomplete? How can I solve my problem?
I want:
- either my Autocomplete to return the same 2 results as my geocoder
- either my geocoder to return a single result, the same as the Autocomplete
(ps: And by the way, I tried typing the same address on the online geocoder of Google on https://developers.google.com/maps/documentation/geocoding/intro and I also get a single address as you can see below. So how come my back-end usage of the geocoding API still return 2 results??)
google-maps google-maps-api-3 autocomplete google-places-api google-geocoder
For the same address entered by the user in the address input, the google Autocomplete API on the front-end (with javacript) returns a single result and thus a single choice for the user.
Whereas the Geocoder API on the back-end (PHP) returns two different results.
I have a back-end validation that gets the address entered by the user thanks to Autocomplete and checks this address with geocoder. If I have no results with the geocoder or more than one result (which is my case, since I get 2 results with the geocoder), I throw an exception.
This is an issue for me because my validation with the geocoder should be able to rely on the Autocomplete.
Please find below my extra explanation
Explanation:
I have a form on my website, where the user enters his address in an address input. This input uses the google Autocomplete API with javascript as follow.
var addressAutocompleteGoogleMaps = new google.maps.places.Autocomplete($myInputJqueryElement[0], {
componentRestrictions: {country: 'fr'},
types: ['geocode']
});
addressAutocompleteGoogleMaps.addListener('place_changed', function() {
var addressAutocompleteSelectedAddress = $myInputJqueryElement.val();
var autocompletionFormattedAddress = addressAutocompleteGoogleMaps.getPlace().formatted_address;
$myInputJqueryElement.val(autocompletionFormattedAddress);
// After having changed my form value to the formatted_address, I submit the form.
});
Now if the user enters the following address
21bis Rue Claude Bernard, 75005 Paris, France
(as you can see there is a space missing between the 21
and the bis
in the address), well on the front end-side, google Autocomplete seems to recognize this address and gives the user a single unique choice. As you can see below:
if I perform a console.log(addressAutocompleteGoogleMaps.getPlace());
, I can see a single result in my console, with the following attributes:
place_id: "ChIJzX6RiOtx5kcRCaog3ti3QTs"
formatted_address: "21bis Rue Claude Bernard, 75005 Paris, France"
geometry: {location: _.P, viewport: _.Q}
But in my back-end, I use the geocoder service of Google and do not tolerate more than one result from the API.
If I use the same address as the formatted_address
of the Autocomplete result on the front-end, which is 21bis Rue Claude Bernard, 75005 Paris, France
, and I submit it to the geocoder API on my back-end with to this URL
https://maps.googleapis.com/maps/api/geocode/json?key=myKey&language=fr®ion=fr&address=21bis+Rue+Claude+Bernard%2C+75005+Paris%2C+France
(as you can see in the URL parameters, there is no space between 21
and bis
because the submitted address by my user, based on the choice of Google Autocomplete does not contain a space either)
I get the following results from the geocoder:
As you can see I get two results with the geocoder from the address 21bis Rue Claude Bernard, 75005 Paris, France
.
But I only get one result with the Autocomplete.
Event the place_ids are not the same. With the autocomplete API, the place_id is ChIJzX6RiOtx5kcRCaog3ti3QT
. But with the geocode API, I get two other place_ids, which are ChIJVeIPVu9x5kcRPHRX59oID5M
and ChIJG9djYOxx5kcR1JtnnCReAxU
.
WHAT I WOULD LIKE
Why does the Google Geocoder not return the same results as the Google Autocomplete? How can I solve my problem?
I want:
- either my Autocomplete to return the same 2 results as my geocoder
- either my geocoder to return a single result, the same as the Autocomplete
(ps: And by the way, I tried typing the same address on the online geocoder of Google on https://developers.google.com/maps/documentation/geocoding/intro and I also get a single address as you can see below. So how come my back-end usage of the geocoding API still return 2 results??)
google-maps google-maps-api-3 autocomplete google-places-api google-geocoder
google-maps google-maps-api-3 autocomplete google-places-api google-geocoder
asked Nov 22 '18 at 20:47
NadjibNadjib
63312
63312
3
Autocomplete and the geocoder are two different services, with different purposes. One uses the Places API, the other doesn't (necessarily). There is no reason they should behave the way you are expecting.
– geocodezip
Nov 23 '18 at 2:47
1) Each place ID can refer to only one place, but a single place can have more than one place ID. This is explained here. 2) Why do you need that extra validation and why do you do it with the geocoder?
– MrUpsidown
Nov 23 '18 at 9:13
add a comment |
3
Autocomplete and the geocoder are two different services, with different purposes. One uses the Places API, the other doesn't (necessarily). There is no reason they should behave the way you are expecting.
– geocodezip
Nov 23 '18 at 2:47
1) Each place ID can refer to only one place, but a single place can have more than one place ID. This is explained here. 2) Why do you need that extra validation and why do you do it with the geocoder?
– MrUpsidown
Nov 23 '18 at 9:13
3
3
Autocomplete and the geocoder are two different services, with different purposes. One uses the Places API, the other doesn't (necessarily). There is no reason they should behave the way you are expecting.
– geocodezip
Nov 23 '18 at 2:47
Autocomplete and the geocoder are two different services, with different purposes. One uses the Places API, the other doesn't (necessarily). There is no reason they should behave the way you are expecting.
– geocodezip
Nov 23 '18 at 2:47
1) Each place ID can refer to only one place, but a single place can have more than one place ID. This is explained here. 2) Why do you need that extra validation and why do you do it with the geocoder?
– MrUpsidown
Nov 23 '18 at 9:13
1) Each place ID can refer to only one place, but a single place can have more than one place ID. This is explained here. 2) Why do you need that extra validation and why do you do it with the geocoder?
– MrUpsidown
Nov 23 '18 at 9:13
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437813%2fgoogle-geocoding-and-autocomplete-do-not-return-the-same-number-of-results%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437813%2fgoogle-geocoding-and-autocomplete-do-not-return-the-same-number-of-results%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Autocomplete and the geocoder are two different services, with different purposes. One uses the Places API, the other doesn't (necessarily). There is no reason they should behave the way you are expecting.
– geocodezip
Nov 23 '18 at 2:47
1) Each place ID can refer to only one place, but a single place can have more than one place ID. This is explained here. 2) Why do you need that extra validation and why do you do it with the geocoder?
– MrUpsidown
Nov 23 '18 at 9:13