Can I restrict geocode results to a specific state in R? - r

I'm using the ggmap geocode with the Google maps API. I have vector of city names in Ohio (city), and I am trying to return coordinates for each of these cities. My code,
coordinates <- geocode(city)
Is mostly returning the correct coordinates, but many of the city names in Ohio are the same as those in other states, so I'm receiving a few incorrect coordinates. Is there an argument I can add to "geocode" so that it only returns coordinates from Ohio?
Thanks!

Related

TomTom reverse Geocode not returning street name for some gps coordinates

For some GPS coordinates, no street name is returned. For example
https://api.tomtom.com/search/2/reverseGeocode/47.532289,-122.251843.json?key=MYKEY&roadUse=[%22LocalStreet%22]&returnRoadUse=true
returns
{"summary":{"queryTime":102,"numResults":1},"addresses":[{"address":{"routeNumbers":[],"countryCode":"US","countrySubdivision":"WA","countrySecondarySubdivision":"King","countryTertiarySubdivision":"Seattle East","municipality":"Mercer Island","postalCode":"98040","municipalitySubdivision":"Mercer Island","country":"United States","countryCodeISO3":"USA","freeformAddress":"Mercer Island, WA 98040","boundingBox":{"northEast":"47.535094,-122.241410","southWest":"47.534766,-122.242287","entity":"position"},"countrySubdivisionName":"Washington"},"position":"47.534897,-122.242287","roadUse":["Publicly Accessible","LocalStreet","Terminal"]}]}
Which contains no street name. Is there anyway to tell the TomTom API to return results that ALWAYS include a street name?
This may be a hack, but if we create a pedestrian route starting with that location (in the middle of Lake Washington) the first instruction starts usually at the closest street that can be navigable, isn't?
These coordinates are pointing to a lake. And the nearest road is some living street with no name. So that is not a perfect example.

How to join spatial data file with geocoded csv file

I have a polygon spatial file that is used to map school zones in nyc, and a csv containing geocoded property locations with longitude and latitude coordinates. I need to join the two together so that every property that is say within school zone 1 is joined to it along with the other unique columns associated with the two datasets.
I've been able to map the school zone data, and property data by themselves in Tableau and QGIS, but I'm unable to join them together in Tableau as they lack a similar unique identifier and I've been unable to get a spatial join in QGIS to work either. I've also attempted a few things in R converting the spatial file to get it's coordinates without success. I'm willing to use any of the resources listed here or anything else that may be needed.

Google Geocode address near a point?

I'm attempting to use Google Geocode to convert a textual address to a longitude/latitude position.
Sometimes, the geocoding operation fails (e.g. the city name is listed as "Rouyn Centre Rouyn-Noranda" instead of "Rouyn-Noranda"). Now, it just so happens that I've got a longitude/latitude point that is near the desired address (say within 1km of the actual address).
Is there a way to look up the coordinates of a street name, number (excluding city, postal code and country) that is "near" a second point?
You could test any subsequent points to see if they're within 1km of the original point using google.maps.geometry.spherical.computeDistanceBetween().

Different latitude and longitude using google maps and ggmap geocode function

I am trying to plot the nearest Walmart store in Canada to a certain post code using ggmap. The function used to get the location is:
goodPoint<-geocode("M1L2K1 walmart canada")
This returned the lat and lon:
> goodPoint
lon lat
1 -79.30113 43.72304
When I check Google map search using the same search term and get the latitude and longitude I get 43.728933,-79.29565.
The difference between the returned latitude and longitude is about 1.1 km, so quite significant.
Can anyone suggest why there is this difference when in the documentation it states that it uses Google Maps for the location? Any suggestions for ways around this?
Have you looked at the actual output from Google geocoder? The geocoder is not the same thing as the maps search. The geocoder resolves addresses, but it afaict does not perform searches such as "find a walmart near M1L2K1 canada".
https://maps.googleapis.com/maps/api/geocode/json?address=M1L2K1%20walmart%20canada&sensor=false
yields the following parsed address:
"formatted_address" : "Scarborough, Ontario M1L 2K1, Kanada"
...
"location_type" : "APPROXIMATE",
...
"types" : [ "postal_code" ]
So in fact, Google even tells you that this is a "postal code resolution" geocoding.
Again, geocoding does not equal search. "Walmart" is not a postal address, but a reasonable search term.

Divide a city into regions in Google Maps

I am trying to divide a certain city into several blocks, each representing North, North-West, North-East, South...and so on. I just need the coordinates of the region boundaries (e.g.: North is between X and Y latitude and between Z and T longitude), so that I can check in my app whether a point belongs to a region or another. The regions should not depend on a certain zoom level's boundaries and they don't need to be the same size (maybe the North part of a city is a little bit larger then the South one).
Any idea how can I "draw" these region boundaries? Thank you!
For boundary data, you would have to do a search. Depends on the city and country. In the US, many municipalities provide this data directly through a city or country web site. Generally it will be in a GIS data format such as a shapefile. You have a number of different options for working programmatically with GIS data formats. I recommend using the GDAL libraries,
particularly ogr2ogr. Once you've got the boundary data, you can draw it on the map using polyline overlays or create a raster images of the data, say using gdal_rasterize. Or you can convert the data to KML using ogr2ogr, and upload it to Google Fusion Tables using Google Docs and overlay it using a FusionTablesLayer.

Resources