I have a Fusion Tables table containing location data for all of the Congressional Districts in Minnesota here.
I want to have a user enter her address, have the Google Maps API geocode it, and spit out the district in which she lives from the table.
I had hoped I could just pick the closest district by using orderBy: ST_DISTANCE in the query. However, this doesn't always return the district the address is actually located in. For example: http://jsfiddle.net/2vGSB/
Assuming it's even possible, how might I return the district that a set of coordinates is located inside of?
EDIT
After digging through the documentation a bit, I found where: ST_INTERSECTS. It appears to be doing what I need: http://jsfiddle.net/DY49c/
Related
I'm created a map in Google Data Studio using zip codes to fill certain area's within the map. However, only 3 zip codes are filled and the other's are not. I tried importing the zip codes as a CSV and Google Sheets and I'm getting the same results.
I made sure the column is being seen as zip codes. I'm not sure what the problem could be.
Data Set (Google Sheets):
zipcode-1
06510
06511
06512
06513
06515
06519
06514
Google Data Studio report
0) Summary
Issue: The geo type, zip code, may exist in multiple countries
Suggestion: Create a calculated field which adds a country value
1) Issue
The problem occurs as Google Data Studio would need to "guess" what the country is. This is because a zip code, while unique to a specific country may not be unique when considering all countries in the world (this also applies to other geo types such as city).
2) Suggestion
Explicitly stating the country would ensure that that values are specific.
This can be achieved using the format:
Geo Field, Country
The values would look like:
06510, United States
A CONCAT of the Zip Code field (titled zipcode-1) with a , followed by the Country (United States) would display the Geo values as expected:
2.1) Calculated Field
CONCAT(zipcode-1, ", ", "United States")
NOTE: In this specific case, the country has to be manually stated within "" as there is no country field, however, if there is a Country field, use: CONCAT(Geo Field, ", ", Country)
2.2) Type
Geo > Postal Code
The output will look like:
zipcode-1
Geo
06510
06510, United States
06511
06511, United States
06512
06512, United States
06513
06513, United States
06515
06515, United States
06519
06519, United States
06514
06514, United States
Publicly editable Google Data Studio report (embedded Google Sheets data source) and a GIF to elaborate:
Is there any way to retrieve different levels of placeIds from a specific placeId? Like when you load the address components of a place, you get 'country' 'city' 'region' and so on... But you only get the names of the different levels of position. Is it possible to get the placeId of the country, city.... ?
When I am storing data in the database, I need to also store the country placeId, city placeId together with the original placeId. Do not want to store the name of the places in the database, when a lot of places have the same names.
As you noticed there are no place IDs in address components array. You cannot get this information executing only place details request. Developers have already created a feature request in Google issue tracker:
Add place_id in each address_components
You can star it to add your vote. In the meantime the workaround to get place IDs for country and locality consists in executing a reverse geocoding requests for coordinates of the original place ID with result type locality and country.
For example, I have a place ID ChIJEygrJmSYpBIRUXOjvF0QSLw. The details request for this place
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJEygrJmSYpBIRUXOjvF0QSLw&key=MY_API_KEY
gives coordinates 41.3886875,2.130554. Now I can execute additional reverse geocoding request to get place IDs of locality and country:
https://maps.googleapis.com/maps/api/geocode/json?latlng=41.3886875%2C2.130554&result_type=country%7Clocality&key=MY_API_KEY
The last one gives me
place ID ChIJ5TCOcRaYpBIRCmZHTz37sEQ (Barcelona)
place ID ChIJi7xhMnjjQgwR7KNoB5Qs7KY (Spain)
I hope this helps!
Using the Google places API I am trying to fetch place_id's. I have issues when trying to fetch a place_id when multiple parts of the place location have the same name. For example: The city Utrecht (in the Netherlands) lies in the municipality of Utrecht, Which lies in the province of Utrecht. They all have the same name.
When I fetch Utrecht from the places service it returns the place_id for city (which is the default for maps incase there are multiple options)
I found a hack/solution to fetch the administrative areas: adding localised name of the thing i'm trying to fetch. For example I can use Gemeente(municipality) or Provincie(province)
Is there a way to request specifically the type of region I want to fetch from the API?
I see that the places API has all this information, but sofar my attempts to fetch the place_id for the administrative_area_level_2 or administrative_area_level_1 without modifying the address are futile.
My "fix" works for the Netherlands but I have 12 more European countries with similar issues hence my question.
The most common solution is using the reverse geocoding with a result type filter.
For example, your sample request for Utrecht returns the following coordinate 52.09073739999999,5.1214201
Now use reverse geocoding with result type.
https://maps.googleapis.com/maps/api/geocode/json?latlng=52.09073739999999%2C5.1214201&result_type=administrative_area_level_1&key=YOUR_API_KEY
This returns place ID ChIJPzM8M01oxkcRsFwejVreAAM for admin area level 1
https://maps.googleapis.com/maps/api/geocode/json?latlng=52.09073739999999%2C5.1214201&result_type=administrative_area_level_2&key=YOUR_API_KEY
This returns place ID ChIJA9Xkz5BoxkcRzAM9YkCZGTs for admin area level 2
Hope it helps!
if I look up this address:
Maanweg 174, 2500 BD The Hague, Nederlands
google maps finds it perfectly. if I look it up this way:
Maanweg 174, The Hague, Nederlands 2500 BD
It does not, because the postal code is out of place.
Now my question: I have 4 fields: Address, City/Region, Country and Postal Code. if the user starts to type the address, a lookup on google maps comes up with a list of addresses the user can pick from. I break the user selection appart and fill-in my 4 fields.
However... if the user changes some part of the address, I need to reconstitute it into a string to feed it to google... but I don't know the proper order. in the Netherlands, the postal code goes after the address. in the US it goes at the end, right before the country.
how can I find out what the proper order is?
There is no unique format, you should use the format as it will be used in the particular country (see: https://developers.google.com/maps/faq#geocoder_queryformat )
According to http://www.bitboost.com/ref/international-address-formats/netherlands/ the order of the first example is correct(for the Netherlands).
So, starting with the following query, I can pass user input to the Geocode API and return a json object/response with the locations details.
http://maps.googleapis.com/maps/api/geocode/json?address=10010
My problem is I have the following query with component filters with the country set to the US (United States). However, if you enter in a zipcode like this which is returning an area in Russia it still renders the map and sets the marker for the users current location.
http://maps.googleapis.com/maps/api/geocode/json?address=16721**&components=country:US**&sensor=false
Do I need to check the short_name within the returned object in a simple if statement and choose whether to issue a map request or not?
I thought component filters would restrict the user to search within the country specified? Then, return ZERO_RESULTS if there is not a match.
Any input, feedback is welcomed. Thanks!
Remove stars from from country name:
http://maps.googleapis.com/maps/api/geocode/json?address=16721**&sensor=false&components=country:US