Output town/city in input rather than full place using Places Autocomplete
up vote
1
down vote
favorite
Currently, I am using regions for my places autocomplete input. I previously used cities before regions as this outputted the town/city in the input.
But now I want to be able to input the postcode or town/city and still have the output as just the town/city.
Basically, I want to use regions but have the output of cities into the input element.
Examples below:
Input: London
Actual Output: London, UK (This is fine)
Desired Output: London, UK
Input: SW1A
Actual Output: London SW1A, UK (This is not fine)
Desired Output: London, UK
Input: NW3 7JR
Actual Output: Hampstead Lane, London NW3 7JR, UK (This is not fine)
Desired Output: London, UK
The Javascript currently using:
//Function for Places Autocomplete
function activatePlacesSearch(){
var input = document.getElementById('id_local_area');
var options = {
types: ['(regions)'],
componentRestrictions: {country: 'gb'}};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
javascript google-maps google-api google-places-api googleplacesautocomplete
add a comment |
up vote
1
down vote
favorite
Currently, I am using regions for my places autocomplete input. I previously used cities before regions as this outputted the town/city in the input.
But now I want to be able to input the postcode or town/city and still have the output as just the town/city.
Basically, I want to use regions but have the output of cities into the input element.
Examples below:
Input: London
Actual Output: London, UK (This is fine)
Desired Output: London, UK
Input: SW1A
Actual Output: London SW1A, UK (This is not fine)
Desired Output: London, UK
Input: NW3 7JR
Actual Output: Hampstead Lane, London NW3 7JR, UK (This is not fine)
Desired Output: London, UK
The Javascript currently using:
//Function for Places Autocomplete
function activatePlacesSearch(){
var input = document.getElementById('id_local_area');
var options = {
types: ['(regions)'],
componentRestrictions: {country: 'gb'}};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
javascript google-maps google-api google-places-api googleplacesautocomplete
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Currently, I am using regions for my places autocomplete input. I previously used cities before regions as this outputted the town/city in the input.
But now I want to be able to input the postcode or town/city and still have the output as just the town/city.
Basically, I want to use regions but have the output of cities into the input element.
Examples below:
Input: London
Actual Output: London, UK (This is fine)
Desired Output: London, UK
Input: SW1A
Actual Output: London SW1A, UK (This is not fine)
Desired Output: London, UK
Input: NW3 7JR
Actual Output: Hampstead Lane, London NW3 7JR, UK (This is not fine)
Desired Output: London, UK
The Javascript currently using:
//Function for Places Autocomplete
function activatePlacesSearch(){
var input = document.getElementById('id_local_area');
var options = {
types: ['(regions)'],
componentRestrictions: {country: 'gb'}};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
javascript google-maps google-api google-places-api googleplacesautocomplete
Currently, I am using regions for my places autocomplete input. I previously used cities before regions as this outputted the town/city in the input.
But now I want to be able to input the postcode or town/city and still have the output as just the town/city.
Basically, I want to use regions but have the output of cities into the input element.
Examples below:
Input: London
Actual Output: London, UK (This is fine)
Desired Output: London, UK
Input: SW1A
Actual Output: London SW1A, UK (This is not fine)
Desired Output: London, UK
Input: NW3 7JR
Actual Output: Hampstead Lane, London NW3 7JR, UK (This is not fine)
Desired Output: London, UK
The Javascript currently using:
//Function for Places Autocomplete
function activatePlacesSearch(){
var input = document.getElementById('id_local_area');
var options = {
types: ['(regions)'],
componentRestrictions: {country: 'gb'}};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
javascript google-maps google-api google-places-api googleplacesautocomplete
javascript google-maps google-api google-places-api googleplacesautocomplete
asked Nov 22 at 15:10
alextford11
1049
1049
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
In short, this will never happen.
Place Autocomplete will always echo the input back to the user, so if part of a postal code is typed, at least that part of the postal code will be part of the prediction. With the types= parameter you can restrict predictions, but in the examples above that will only cause no predictions to be returned.
There are a few things you can do:
- Take the
structured_formatting.secondary_text
which, while not always exactly the "London, UK" level you want, it is always available on the Place Autocomplete response, so no need to do even a Details request for the Place ID. - Request details for this Place ID (from either Geocoding API or Place Details) and reverse geocode its location latlng in the Geocoding API. That will give you all political features that contain the latlng. Then you need to be careful about which one represents the "city" or whatever it is you want. See explanation about this in https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete-addressform
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
In short, this will never happen.
Place Autocomplete will always echo the input back to the user, so if part of a postal code is typed, at least that part of the postal code will be part of the prediction. With the types= parameter you can restrict predictions, but in the examples above that will only cause no predictions to be returned.
There are a few things you can do:
- Take the
structured_formatting.secondary_text
which, while not always exactly the "London, UK" level you want, it is always available on the Place Autocomplete response, so no need to do even a Details request for the Place ID. - Request details for this Place ID (from either Geocoding API or Place Details) and reverse geocode its location latlng in the Geocoding API. That will give you all political features that contain the latlng. Then you need to be careful about which one represents the "city" or whatever it is you want. See explanation about this in https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete-addressform
add a comment |
up vote
0
down vote
In short, this will never happen.
Place Autocomplete will always echo the input back to the user, so if part of a postal code is typed, at least that part of the postal code will be part of the prediction. With the types= parameter you can restrict predictions, but in the examples above that will only cause no predictions to be returned.
There are a few things you can do:
- Take the
structured_formatting.secondary_text
which, while not always exactly the "London, UK" level you want, it is always available on the Place Autocomplete response, so no need to do even a Details request for the Place ID. - Request details for this Place ID (from either Geocoding API or Place Details) and reverse geocode its location latlng in the Geocoding API. That will give you all political features that contain the latlng. Then you need to be careful about which one represents the "city" or whatever it is you want. See explanation about this in https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete-addressform
add a comment |
up vote
0
down vote
up vote
0
down vote
In short, this will never happen.
Place Autocomplete will always echo the input back to the user, so if part of a postal code is typed, at least that part of the postal code will be part of the prediction. With the types= parameter you can restrict predictions, but in the examples above that will only cause no predictions to be returned.
There are a few things you can do:
- Take the
structured_formatting.secondary_text
which, while not always exactly the "London, UK" level you want, it is always available on the Place Autocomplete response, so no need to do even a Details request for the Place ID. - Request details for this Place ID (from either Geocoding API or Place Details) and reverse geocode its location latlng in the Geocoding API. That will give you all political features that contain the latlng. Then you need to be careful about which one represents the "city" or whatever it is you want. See explanation about this in https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete-addressform
In short, this will never happen.
Place Autocomplete will always echo the input back to the user, so if part of a postal code is typed, at least that part of the postal code will be part of the prediction. With the types= parameter you can restrict predictions, but in the examples above that will only cause no predictions to be returned.
There are a few things you can do:
- Take the
structured_formatting.secondary_text
which, while not always exactly the "London, UK" level you want, it is always available on the Place Autocomplete response, so no need to do even a Details request for the Place ID. - Request details for this Place ID (from either Geocoding API or Place Details) and reverse geocode its location latlng in the Geocoding API. That will give you all political features that contain the latlng. Then you need to be careful about which one represents the "city" or whatever it is you want. See explanation about this in https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete-addressform
answered Nov 29 at 12:03
miguev
3,6011135
3,6011135
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53433818%2foutput-town-city-in-input-rather-than-full-place-using-places-autocomplete%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