Reputation: 1
Google Geocoder finds the nearest occurrence of the store if the store does not exist in the given address. ex) When I try to geocode these two different locations: (Shell, 5175 Walker Rd, Windsor, N9A6J3, ON) (Shell, 3178 Dougall Ave, Windsor, N9E1S6, ON)
Google returns the location of Shell in 3178 Dougall Ave since the Shell in Walker rd is closed. However, for the nature of my work name(Shell) cannot be taken out since it requires the exact location of the store, and I want it to show the location(Coordinates) of the address itself instead of looking for the nearest store with the same name for the stores that are recorded to be closed or even not existing in the google database. Of course, store name should be put in count if the stores do exist within the address given.
Would there be a special function that can run the geocoder with the name if the store exists, and run it without the name if the store does not exist?
Upvotes: 0
Views: 240
Reputation: 32158
If your intention is getting businesses you should look into Places API. Note that Geocoding API was designed to work with street addresses and it not always returns businesses related to certain address.
For your example I would suggest applying a Find Place requests of Places API.
For the first address 'Shell, 5175 Walker Rd, Windsor, N9A6J3, ON' the find place request
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Shell%2C%205175%20Walker%20Rd%2C%20Windsor%2C%20N9A6J3%2C%20ON%7Ctextquery&inputtype=textquery&fields=formatted_address,geometry,name,place_id&key=YOUR_API_KEY
returns the following candidates
{
candidates: [
{
formatted_address: "5175 Walker Rd, Windsor, ON N9A 6J3, Canadá",
geometry: {
location: {
lat: 42.239329,
lng: -82.964381
},
viewport: {
northeast: {
lat: 42.24063827989272,
lng: -82.96303847010729
},
southwest: {
lat: 42.23793862010728,
lng: -82.96573812989273
}
}
},
name: "WALKER ROAD MOBIL",
place_id: "ChIJL-RKvyUpO4gRIGCJe4hvExU"
},
{
formatted_address: "5175 Walker Rd, Windsor, ON N9A 6J3, Canadá",
geometry: {
location: {
lat: 42.23932629999999,
lng: -82.9643768
},
viewport: {
northeast: {
lat: 42.24063672989271,
lng: -82.96303407010728
},
southwest: {
lat: 42.23793707010727,
lng: -82.96573372989272
}
}
},
name: "Shell",
place_id: "ChIJXfjgKposO4gRR-AjWaZ2HXI"
}
],
status: "OK"
}
For the second address 'Shell, 3178 Dougall Ave, Windsor, N9E1S6, ON' the find place request
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Shell%2C%203178%20Dougall%20Ave%2C%20Windsor%2C%20N9E1S6%2C%20ON%7Ctextquery&inputtype=textquery&fields=formatted_address,geometry,name,place_id&key=YOUR_API_KEY
returns the following
{
candidates: [
{
formatted_address: "3178 Dougall Ave, Windsor, ON N9E 1S6, Canadá",
geometry: {
location: {
lat: 42.2688825,
lng: -83.0107531
},
viewport: {
northeast: {
lat: 42.27028142989272,
lng: -83.00927217010728
},
southwest: {
lat: 42.26758177010728,
lng: -83.01197182989273
}
}
},
name: "Shell",
place_id: "ChIJwZ78fRcsO4gR9Oyl2IVqB6o"
}
],
status: "OK"
}
So you get both addresses in these responses.
Upvotes: 0