How to check if address in within region on Google Maps API
I have an address string E.g. "12 Swiss Ave, Gonville, Wanganui, New Zealand"
Given this address I need to work out if the address is within the North or South island of New Zealand.
If I pass the address to the google maps api the data I get back is below, unfortunately though it doesn't tell me what island it is in. So, how can I check this?
{
"results": [
{
"address_components": [
{
"long_name": "12",
"short_name": "12",
"types": [
"street_number"
]
},
{
"long_name": "Swiss Avenue",
"short_name": "Swiss Ave",
"types": [
"route"
]
},
{
"long_name": "Gonville",
"short_name": "Gonville",
"types": [
"sublocality",
"political"
]
},
{
"long_name": "Wanganui",
"short_name": "Wanganui",
"types": [
"locality",
"political"
]
},
{
"long_name": "Manawatu-Wanganui",
"short_name": "Manawatu-Wanganui",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "New Zealand",
"short_name": "NZ",
"types": [
"country",
"political"
]
},
{
"long_name": "4501",
"short_name": "4501",
"types": [
"postal_code"
]
}
],
"formatted_address": "12 Swiss Avenue, Gonville, Wanganui 4501, New Zealand",
"geometry": {
"location": {
"lat": -39.9444245,
"lng": 175.0239575
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": -39.9430755197085,
"lng": 175.0253064802915
},
"southwest": {
"lat": -39.9457734802915,
"lng": 175.0226085197085
}
}
},
"types": [
"street_address"
]
}
],
"status": "OK"
}
Solution 1:
One option would be to get the polygons for the two islands and do point in polygon analysis on the geographic location.
Example using Polygons defined by KML and geoxml3
Proof of concept (using geoxml3 and modified KML from gadm.org)
============ older option using fusion tables, no longer works =============
Example using FusionTables (note: no longer works, Fusion Layers was turned down December 2019)
Proof of concept (using the Natural Earth data set in Fusion Tables and a "state to island" map) (note: also no longer works)