How the country code of a venue is generated? - geolocation

I'm developing an APP using FS API and I need to geolocalize a venue. Nothing particularly difficult, just "US" or "Non-US".
I though of using the country code (CC fields) which come with every venue object, but I'm not sure how this country code is calculated:
a) Is something you infer using the lat and lon of the venue, and therefore something FS calculates directly with Geospatial queries?
b) Is something the user insert manually (not only the CC but the country itself) and therefore is something which can be missing of be mispelled / misinserted?
Cheers,
Alfredo

The country information is built up from a variety of sources, including geolocation and user input. The input is validated though, so there should not be any invalid country codes. You can expect that the country code will be an accurate representation of where the venue is located.

Related

Foursquare API - Search By Address

I am using the venues/search API in my app and I am getting some strange results: https://developer.foursquare.com/docs/venues/search.
If I send in the query "1 Irving", as if a user is searching for an address, the list of results returned by Foursquare contains irrelevant venues. From looking at the documentation, I would guess that this is because the "query" parameter of the API is only searching against venue names, and not addresses.
If that is the case, does anyone know if there is any way to get the API to search against address information also? It seems the Foursquare and Swarm apps both do this when searching, as the results for "1 Irving" are much more relevant when I try there.
Edit: including screenshot from Foursquare app
In the venues/search documentation it mentions that if you set intent=match you can include an address parameter.
Finds venues that are are nearly-exact matches for the given
parameters. This intent is highly sensitive to the provided location.
We recommend using this intent only when trying to correlate an
existing place database with Foursquare's. The results will be sorted
best match first, taking distance and spelling mistakes/variations
into account.
query and ll are the only required parameters for this intent, but
matching also supports phone, address, city, state, zip, and twitter.
There's no specified format for these parameters—we do our best to
normalize them and drop them from the search if unsuccessful.
However you still need to provide a query parameter that would be the venue name. I don't believe an endpoint exists to lookup a venue with nothing but an address.
Just from taking a quick look at the docs, it seems like you can just pass the location in as the near object rather than the query object. The docs specifically say "A search term to be applied against venue names."

How to query for distance from NSString addresses in Parse?

For my iOS application, I need to organize a list of Parse objects by their distance from the user's current location. Each of the Parse objects has an attribute for location, but the location is a regular address in the form of an NSString, rather than GPS coordinates or a CLLocation.
I have two questions for this situation:
How do I find the distance between an NSString location and the user's current location?
How do I query for the distance in Parse (for example, only display the objects within 5 miles)?
Thanks for any help!
To perform distance queries, you need a GeoPoint. There are many ways to look up a GeoPoint given a string address.
You could create an Cloud Code after-save method that uses Google to lookup the GeoPoint and add it to the record. Looking up the GeoPoint from a string is an expensive operation, you only want to do this once for each data point when the data changes.
To attempt to find distance based on a string address within a query (would require every record to be evaluated every time) would unfairly tax the geo-lookup facility and probably be a breach of the terms of use.
Once you have an actual GeoPoint in your data then the query is quite easy, as per the documentation:
To limit the results using distance check out whereKey:nearGeoPoint:withinMiles, whereKey:nearGeoPoint:withinKilometers, and whereKey:nearGeoPoint:withinRadians.

Web Service for Geo Location (Get biggest Cities within an state)

Is there are (web) service which offers a Geo Location API?
For example:
I have the German State "Baden-Württemberg", now I want to get a result which are the biggest city's (for example order by population).
My problem is little bit abstract, but hope someone can understand it.
This is not exactly what you are looking for, but I think it is a step in the direction if you are willing to setup your own database to query. The United Nations Statistical Division (UNSD) keeps a dataset of the largest cities > 100,000 population. You can find it at this link. Note that it does not show what state (1st level administrative division) the city is within, just the country.
http://unstats.un.org/unsd/demographic/products/dyb/dyb2011/Table08.xls
I have created a CSV version of the data (using semi-colons as delims) you can use as well:
http://www.opengeocode.org/cude1.1/UN/UNSD/dyd2011-pop100k.zip
OpenGeoCode.Org is an open data project where we take national and international publicly available datasets and convert them into a common CSV format.
Andrew

Complex fuzzy string matching in iOS

I'm writing an iOS application that pulls events from a public Google calendar, pulls out the free-form "Location" field, and drops a pin on a map corresponding to the given location. I want to make the app as flexible as possible using some kind of string search or fuzzy matching algorithms, but I'm not sure where to begin.
There are several things a calendar moderator may enter into the Location field:
A building name and room number (e.g. Foo Hall Room 123)
A building abbreviation and room number (e.g. FOO 123)
A shorthand room or location name (e.g. Foo)
Currently, I have a sqlite database composed of one table, each row storing a latitude, longitude, full building name (Foo Hall), and standardized building abbreviation (FOO).
I want to take the moderator's free-form string and obtain the correct coordinates from the database (if present).
I've tried using LIKE '%FOO%' and similar patterns, as well as Levenshtein Distance, but I run into issues, for instance if the actual building name is "Example Foo and Bar Building" and the location entered by moderator is "Example Bar Building".
The three options I've considered are...
Force the moderator to enter in a standardized abbreviation or building name. This could potentially be a tedious process for the calendar moderators, so I'm trying to avoid this if possible.
Do a crude substring search that checks if the entered string is contained anywhere in the database string. This is what my university does on their website, but it obviously isn't very flexible.
Implement a more complex fuzzy string matching algorithm that provides maximum flexibility but will take an order of magnitude more time to implement. If the right one already exists, that would be the ideal solution!!
Which of these options (if any) seems the best? Is there a better alternative that I haven't thought of? Is there a library that does what I need and I just haven't found it yet?
Thanks in advance for any help!

What's the best way to lookup the US county a US city resides in?

I'm looking for the best/easiest way to programmatically grab the name of the US county a given US city resides in. It doesn't seem there's a straightforward API available for such a (seemingly simple) task?
You can download a freely-available database of county/city/zip code info such as this one:
http://www.unitedstateszipcodes.org/zip-code-database/ (no need to register or pay)
Import it whole, or a subsection of it, into a local, persistent data store (such as a database) and query it whenever you need to look up a city's county
Note: County info has disappeared from the originally-linked .csv file since this answer was posted.
This link no longer contains county information: http://federalgovernmentzipcodes.us/free-zipcode-database.csv
1) Cities span counties
2) Zips span both cities and counties, not even on the same lines
Any solution that uses zip as an intermediary is going to corrupt your data (and no, "zip+4" won't usually fix it). You will find that a city-to-zip-to-county data map (#2) has a larger number of city-to-county matches than the more accurate model (#1)--these are all bad matches.
What you're looking for is free census data. The Federal Information Processing Standards (FIPS) dataset you need is called "2010 ANSI Codes for Places": https://www.census.gov/geographies/reference-files/time-series/geo/name-lookup-tables.2010.html
Census "places" are the "cities" for our question. These files map "places" to one or more county.
It will not be easy to use geospace functions for this task because of the odd polygon shaped of counties and the point locations of cities.
Your best bet is to reference a database of cities and their respective counties, though I don't know where you could find one.
Maybe Texas publishes one?
CommonDataHub doesn't contain this information.
Here is a bit of code to programmatically grab the name of a US county given a single US city/state using the Google Maps API. This code is slow/inefficient and does not have any error handling. However, it has worked reliably for me to match counties with a list of ~1,000 cities.
#Set up googlemaps API
import googlemaps
google_maps = googlemaps.Client(key='API_KEY_GOES_HERE')
#String of city/state
address_string = 'Atlanta, GA'
#Geocode
location = google_maps.geocode(address_string)
#Loop through the first dictionary within `location` and find the address component that contains the 'administrative_area_level_2' designator, which is the county level
target_string = 'administrative_area_level_2'
for item in location[0]['address_components']:
if target_string in item['types']: #Match target_string
county_name = item['long_name'] #Or 'short_name'
break #Break out once county is located
else:
#Some locations might not contain the expected information
pass
This produces:
>>> county_name
Fulton County
Caveats:
code will break if google_maps.geocode() is not passed a valid
address
certain addresses will not return data corresponding to 'administrative_area_level_2'
this does not solve the problem of US cities that span multiple counties. Instead, I think the API simply returns the county associated with the single latitude/longitude associated with address_string
The quickest and most non-evasive way might be to use a JSON/XML request from a free geolocation API (Easily found on Google). That way you don't need to create/host your own database.

Resources