Google Api key location and address solution - api

I am developing a mobile app and website that allow users to advertise their items only in the UK. However, I don't want the return address to show the full address of the seller on the advert but instead should show the town and the city
For example, 395 Frances Street, London, SE18 5JU, England, UK. This address is in Greenwich town. I just want the location on the advert to show only the town and the city. For example (Greenwich, London)
I mean I would like to restrict the address not to show the full address but specific town and city. Please what is the best solution and how do I achieve this. any suggestion would be appreciated.

You can use Geocoding API if you have the street address and check the "address_components" in the response or use the Places API to request Address Components about the place (Place.Field.ADDRESS_COMPONENTS if using the Places SDK for Android and GMSPlaceFieldAddressComponents if using the Places SDK for iOS). Both will return the address broken into components so you can select which components to display. Each component type is explained in documentation though it may take some experimentation to know which administrative_area_level_N corresponds to the concepts of "town" and "city" in your area.

Related

Accessing locations in Objective-C

For my app I will need to access different town and store data for each town. Basically it will be a 2d array with one dimension being the town and the next the data. I was just wondering (using Xcode and Objective C) how I could access every town in a country (I'm looking at the UK if that helps). I don't need it on a map I just need it so people can store data relative to their town simply by searching for the town and adding their data to the array for that town. Thanks in advance!
There are a couple of ways to do it. If you want to use the user's device GPS to identify its location, than you can use the Google Places API that you can install through cocoapod
If you want to perform a search, you can obtain a API key from Google and then use their URL based search. For example, this URL should return a list of Starbuks in Seattle. There are more parameters that can be set and can apply to your case.
https://maps.googleapis.com/maps/api/place/textsearch/json?query=starbucks+seattle&sensor=false&key=YOUR_API_KEY

Proximity search in Postgresql for Street Addresses

I have a list of street addresses with city and state but no zip code. These addresses won't geocode with Google's API because they are building permit addresses with no mailbox or new construction addresses they have yet to be built.
I would like to do a kind of proximity search that will find the nearest address which does have a geocode. Is this possible?
I've read about doing this with zip codes but I don't have those and I am worried they are still too general.

Geocoding with rails search

I've been running into some location based searches using the Google Maps API (more of a structural issue on my end than any criticism of the mapping api)
For example, if a user searches for "Victoria, Canada" it will bring up results for "Victoria, Canada" as expected. However, if a user searches for "Canada," google returns a longitude and latitude for the middle of the country, which is essential for correctly centering the map. However, it will not display any results since the nearest location is too far away from the location returned by google. I'm filtering out results that are about 20 miles away.
Can the Google Maps API return anything that I could use to tell if a user has entered a state or country name? If not, has anyone developed a work around solution?
Ideally, I would like to avoid just ordering the results by nearest location. I don't want items for "Spain" showing up at the bottom of a list when a user searches for "United States." I would try to determine if the query is a state or country prior to the search, but this seems very daunting task given the different possible spelling of country and region names. If I was only expecting english spellings, it would be a much easier approach.
Assuming this is a form on a site that has a controller parse the form and send the request to Google's API, you could break the form out into address, city, state, and country (if needed) form elements then make the address and city required fields.
I'm doing a similar approach with a site I'm building using Google Places API and it seems to work for me.

How to validate a location address in form?

I want to validate that the postal address filled in by a user is correct.
Assuming that we have the fields street, street_number, postal_code, city and country
How can show errors when the user, types in that his country is France and is city is New York?
or
How can I detect that a postal code doesn't correspond to the city?
Is there a strategy to address this issue with Ruby On Rails or shall I just trust the user entries ?
There are several companies that publish US ZIP code directories, typically not terribly expensive, and some even come with lat/lon data. This is the most common way of validating city and state in the US or North America. Worldwide postal codes to country and city is likely to be a harder problem, or at least a more expensive one.
Another approach would be to use the Google Maps API, perhaps in conjunction with the data you can get from location-aware browsers (all modern ones). To be honest, it's been a while since I have used the API, but seem to recall you can get pretty detailed information given a lat/lon. Google now charges for high use of the Maps API, but if your site has even moderate traffic, you're probably still in the free zone.
At some level, you'll have to trust users. I remember a while back we found anomalies in user reported zipcodes in our database -- seemed like everyone lived in Beverly Hills, CA. This was around 2000, when the original version of the TV show "90210" was still around -- that's the zipcode :-).
Have you considered just a jQuery plugin to verify addresses for you? It's free for many users, up to 250 lookups/mo, and is always current (no need for you to maintain a database).
Incidentally, I work at SmartyStreets. There's also a ZIP code API to look up if cities match ZIP codes and vice-versa. Either way, we've put a lot of effort into making the user experience positive, even when the address they type isn't totally valid.

How do search engines link a url to a street address for their map view?

For instance, you search for 'company x, Austin TX' and Google returns a map at the top of the page with a marker on it, the location of company x, and company x's website. How is that information collected? Does someone at the business address have to somehow manually associate the physical address with a web address?
The data is collected first by telephone companies who make available the name, address, city, state, zip, and phone number (think phone books). Beyond that, any extra data like websites, images, descriptions are collected by various services and shared.
If you start putting your number in the phone book you tend to get spammed, at least in the UK. http://google.com/local/add is where you can add your business details to google.