Google Geocode/Places API: search zip code - get addresses connected to it, possible? - autocomplete

So, another Google API question but I didn't find any threads for my needs.
I'm trying to implement a basic zip code search with Google API in plain Javascript (tested both Geocode and Places with Autocomplete).
User should be able to search on a specific zip code and get street names returned which are connected to that zip code (and simply choose the correct address).
I have no problems getting results back using either one of the APIs but I can't wrap my head around Googles documentation for it since nothing tells you if this is possible or not.
I've tested a couple of different types to send in the options setting but none actually returns an array of addresses.
Been thinking if reverse geocoding would be a solution but seems a bit hacky and also would require multiple requests..
Simply out of ideas, any help appreciated.
types: ['geocode'],
componentRestrictions: { country: 'SE' }
}
let autocomplete;
function initialize() {
autocomplete = new google.maps.places.Autocomplete(
document.getElementById('postalCode'), options);
autocomplete.setComponentRestrictions({'country': ['SE']})
autocomplete.setFields(['address_component']);
autocomplete.addListener('place_changed', fillInAddress);
}

Please note that it is currently not supported for the Geocoding or Places API to show a list of addresses by zip code.
Places Autocomplete is designed to return place predictions based on the user input and perceived relevance. While the Geocoding API is designed to convert a single string address to coordinates and vice versa.
You can use this Geocoder tool to test this.
There is also a related feature request for this functionality, it's marked as Infeasible/Intended behavior but you can still star it to receive updates:
https://issuetracker.google.com/issues/64769088
Starring the issue also provides valuable feedback on the importance of the issue to customers, and increases the issue's priority with the product engineering team.

Related

async autocomplete service

Call me crazy, but I'm looking for a service that will deliver autocomplete functionality similar to Google, Twitter, etc. After searching around for 20 min I thought to ask the geniuses here. Ideas?
I don't mind paying, but it would great if free.. Also is there a top notch NLP service that I can submit strings to and get back states, cities, currencies, company names, establishments, etc. Basically I need to take unstructured data (generic search string) and pull out key information with relevant meta-data.
Big challenge, I know.
Sharing solutions I found after further research.
https://github.com/haochi/jquery.googleSuggest
http://shreyaschand.com/blog/2013/01/03/google-autocomplete-api/
If you dont want to implement it yourself, you can use this service called 'Autocomplete as a Service' which is specifically written for these purposes. You can access it here - www.aaas.io.
you can add metadata with each record and it returns metadata along with the matching results. Do check out demo put up on the home page. It has got a very simple API specifically written for autocomplete search
It does support large datasets and you can apply filters as well while searching.
Its usage is simple - Add your data and use the API URL as autocomplete data source.
Disclaimer: I am founder of it. I will be happy to provide this service to you.

Bing search API with DisableLocationDetection not working

The Bing search API is using my (or my server's) location even when I set the appropriate option. I would like it to provide a location agnostic response.
Am I misunderstanding the documentation? Is this syntax right?
http://api.bing.net/json.aspx?Appid=<XXX>&query=microsoft&sources=news&options=DisableLocationDetection
Thanks in advance
The syntax is right. According to the doc, the DisableLocationDetection option prevents Bing from inferring location from the query itself ("microsoft" in your example), but not from the properties of the request, such as server's IP.
News requests can specify LocationOverride parameter to get news from a particular US state. Also, if you're having troubles with automatic market detection (if your server is in another country, for example), you can specify Market parameter to override the market detection.
If this still doesn't help you, can you update the question to provide an example of a query which gives you the bad result?

List / database of valid addresses for geolocation / geospatial testing

I'm running some geospatial tests to demonstrate use of the MongoDB geo APIs. The problem is that I don't have a list of valid addresses with which I can test.
The idea is to query the latitude and longitude through Bing Maps as my sample application is a job search website where the locations I will be indexing to query against would be entered as listing for new job opportunities and would be entered using addresses rather than latitude and longitude coordinates.
Any help would be much appreciated!
I don't suspect Microsoft provides a list of fake locations that will register to valid lat/long coordinates on Bing (for this exact purpose or similar), but if they do...that would be equally acceptable.
FWIW, I did thoroughly check Microsoft's documentation and found nothing on this.
Alternatively, I could just query common places like Starbuck's or POI's (probably what I'll end up doing), but it would be nicer if there were a testing mode where you could use addresses that would register with Bing. Microsoft, in case you happen to subscribe to Stack Overflow tags, I would post this suggestion on the Bing community forums but there is no way to post an answer or question there, please fix this.
Decided just to use the Bing Maps API to query some popular companies although this is not ideal.

Get zip code from latitude, longitude?

I want to get zip code from users current location(Latitude, Longitude), I had used MKReverse Geocoder delegate methods, but sometimes I am not able to get zip code information based on latitude & longitude (valid values). Are there any other alternatives for MKReverseGeocoder ? ZipCode database are specific to countries, that's why I don't want to use them. Any other idea or clue?
Thanks
Consider the GeoNames web service. It's a complete geocoding/reverse geocoding suite under a Creative Commons attribution license. You can either download their data, or hit their web service. The best thing is, they don't require any API keys or licensing silliness--you just hit their web app and bang you got data.
Here's an example: http://ws.geonames.org/findNearbyPostalCodesJSON?formatted=true&lat=36&lng=-79.08 That'll return you a JSON object for the zip codes around the Chapel Hill, NC area.
It's also international. Here's Seaford, England, and the only difference is the lat/lng pair I'm sending: http://ws.geonames.org/findNearbyPostalCodesJSON?formatted=true&lat=50.5&lng=0.08
Then you need to learn to make web requests and parse JSON (if you don't already have a grip on those things), and you're all set.
This is actually a tricky question. Using a geocoding solution like GeoNames is likely to lead to major errors for a lot of queries. The reason for this is that GeoNames by looking up the record in their database that is closest to your query point and then returning the ZIP code they have on record for that point. This works great when your query point is right on top of a record in their database, but can lead to errors otherwise. For example, if their nearest record is a few blocks away in a different ZIP code, you'll get the wrong answer.
The US Census Bureau has created maps of the ZIP codes:
https://www.census.gov/geo/reference/zctas.html
Please see their notes on that page.
I have also worked on a project that uses the Census maps to provide an API that gives back the ZIP code for a given latitude and longitude. It is at:
http://askgeo.com
We offer both a web API and a Java Library that you can run on your own server. The library has excellent performance. Since our site offers additional information than just the ZIP code, you can read about our ZIP code service here:
http://askgeo.com/database/UsZcta2010
And you read about the documentation for the Web API here:
http://askgeo.com/#web-api
The GeoNames methodology is fundamentally flawed for this type of query. If you are looking for the polygon that contains a given query point, you need a map with the polygons, and you need a spatial index to provide fast look-ups. GeoNames has neither. AskGeo has both.
If you have a free db (available from that site? Just search for zip code database and you'll see it)
then you can run an internal SQL query testing for nearby lat/longs. That way you won't need to worry about licensing a web service.
You have three options then. SQL BETWEEN statement, the hypotenuse equation, or Haversine. Haversine being the best, luckily it's tutorial'd elsewhere
EDIT:
Couple of other options I've seen recently:
http://developer.yahoo.com/geo/placefinder/guide/index.html
http://jamiethompson.co.uk/projects/2010/04/30/an-open-free-uk-postcode-geocoding-web-service/
http://www.postcodeanywhere.co.uk/geocoding-service/api.aspx
--
Take a look at the Google Maps API - Reverse Geocoding (only useful if embedding results in a Google Maps interface).
Sample code here:
Get Zipcode from results[1].formatted_address
https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse

Integrate Google Maps API into an iPhone app

Update: iPhone SDk 3.0 now addresses the question here, however the NDA prevents any in depth discussion. Log in to the iPhone Dev Center if you need more info.
Ok, I have to admit I'm a little lost here.
I am fairly comfortable with Cocoa, but am having trouble picking up the bit of javascript needed to solve this problem.
I am trying to send a request to Google for a reverse geo code.
I have looked over the Google documentation I have viewed here:
http://code.google.com/apis/maps/documentation/index.html
http://code.google.com/apis/maps/documentation/geocoding/
Even after a rough reading, I am missing a basic concept:
How do I talk to google? In some examples, they show a url being sent to google (which seems easy enough), but in others they show javascript. It seems for reverse geocoding, the request might be be harder than sending the url with some parameters (but I hope I am wrong).
Can someone point me to the correct way to make a request? (In objective-C, so I can wrap my head around it)
UPDATE - iPhone 0.3 includes MapKit, which will hopefully be significantly faster than using the JS API. The blurb says that it will include reverse geocoding.
You can't make a request directly in objective-C, at least not within the terms of the Google API. The Google API is written in Javascript. You could use an objective-c to JS bridge, as the Google Maps Component does, but that doesn't really solve the issue - you're still making JS calls!
Unfortunately, that means you
a) need to use a webview
b) need to use the JS API which is slow... compare with the Google Maps application which uses a completely different OTA protocol (try packet sniffing it).
The Google Maps Component is, however, a useful tutorial in how to make simple calls to the API.
I have created SVGeocoder, a simple forward and reverse geocoder class for iOS. It uses the Google Geocoding API, returns SVPlacemark objects (an MKPlacemark subclass with a coordinate property) and uses blocks.
This is how you geocode an address string:
[SVGeocoder geocode:addressString
completion:^(NSArray *placemarks, NSError *error) {
// do something with placemarks, handle errors
}];
You can also reverse geocode a coordinate like this:
[SVGeocoder reverseGeocode:CLLocationCoordinate2DMake(45.53264, -73.60518)
completion:^(NSArray *placemarks, NSError *error) {
// do something with placemarks, handle errors
}];
The easiest way to get a Google map using Cocoa is to use the "Static Maps API". In practice, you need to prepare an NSURL that you use to contact Google. You get back your map as NSData, that you transform to an NSImage. Note that you can do both geocoding and reverse geocoding. You can also embed markers on the map. However, you loose the full controls you have access to if you use their JavaScript API.
Take a look at their reference guide here:
http://code.google.com/apis/maps/documentation/staticmaps/
Now that apple have release the MapKit API for OS 3.0, I think your question has been answered. Having looked at the API docs, I can see a heck of a lot of potential! I still would like to see reverse geocoding webservice from Google, but Yahoo will do in the meantime.
For your information: The reverse geocoding API from Google for requests by XML isn't public, so it's illegal to use. The only legal way is going through their JavaScript-API, which as you found out is harder to do in Cocoa than to simply send an HTTP request.
Alternatives: Reverse geocoding with simple XML/JSON requests is also available from Geonames or Yahoo.
Since iOS5 we have the following options as stated in the development doc:
* "A geocoder object uses a network service to convert between latitude and longitude values and a user-friendly placemark, which is a collection of data such as the street, city, state, and country information. Reverse geocoding is the process of converting a latitude and longitude into a placemark. Forward geocoding is the process of converting place name information into a latitude and longitude value. Reverse geocoding is supported in all versions of iOS but forward geocoding is supported only in iOS 5.0 and later."*
You can now use a CLGeocoder object.
Also try to take a look at google maps component.
Actually, I did not meant reverse geocoding as "translating a point into a human-readable address", but rather visualizing a point using a Google Map (that can also, depending on the accuracy level, show a human-readable address). This is the basic functionality that was required.
In practice, I just wanted to suggest the static maps API as a clean and fast way to:
1) given the coordinates obtained from the iPhone GPS sensor, retrieve a Google Map showing the point
2) given an address, transform it in the corresponding geographical coordinates and then use the coords to retrieve a Google Map showing the address given
Both are possible using simple NSURLs involving the staticmap and geo services
http://maps.google.com/staticmap?
http://maps.google.com/maps/geo?
passing of course the needed parameters to provide a suitable query string.
Kind regards
The big issue of course, is that the license agreement of both google and yahoo state you can't use these API's in "commercial applications". would hate to pub an app on the app store only to have it taken down and sued by yahoo or google. In reading the iPhone 3.0 map api and associated license this isn't mentioned but if you want an app to run on phones not upgraded....
Is there an answer for this that won't get one in trouble?
http://blog.cloudmade.com/2009/06/12/how-to-get-forward-geocoding-in-iphone-mapkit/
CloudMade seems to be an open-source map/location provider - the above blog post lists details on how to get forward geocoding.