Returning neighborhood based on address with Google geocoder/API
Asked Answered
B

4

4

Is there any way to effectively/accurately pull out a neighborhood within a city based on a passed in address, zip, city, state to the Google Geocoder?

Whenever I try to do it via HTTP (ideal solution) It returns the following info

<kml>
−
<Response>
<name>anthonys cookies san francisco California</name>
−
<Status>
<code>200</code>
<request>geocode</request>
</Status>
−
<Placemark id="p1">
<address>San Francisco, CA, USA</address>
−
<AddressDetails Accuracy="4">
−
<Country>
<CountryNameCode>US</CountryNameCode>
<CountryName>USA</CountryName>
−
<AdministrativeArea>
<AdministrativeAreaName>CA</AdministrativeAreaName>
−
<SubAdministrativeArea>
<SubAdministrativeAreaName>San Francisco</SubAdministrativeAreaName>
−
<Locality>
<LocalityName>San Francisco</LocalityName>
</Locality>
</SubAdministrativeArea>
</AdministrativeArea>
</Country>
</AddressDetails>
−
<ExtendedData>
<LatLonBox north="37.8454521" south="37.7043396" east="-122.2913561" west="-122.5474749"/>
</ExtendedData>
−
<Point>
<coordinates>-122.4194155,37.7749295,0</coordinates>
</Point>
</Placemark>
</Response>
</kml>

If you notice, the "locality name" still says San Francisco?

At this point I am open to making use of the Javascript API/call as opposed to the HTTP call, it just seemed like overkill (and more of a headache) for what I am trying to do.

Ideally, I need this to work in San Francisco for now, but it would be nice if I could get it to work for all of the major U.S. Cities.

Brannon answered 9/12, 2009 at 1:46 Comment(2)
What locality/neighbourhood name would you be expecting instead of San Francisco in this case? I have seen Google Maps deal with districts in the past.Christogram
I was hoping for something like "The Mission" OR "Mission" in this case. I too know that Google should be more than capable of handling a query like this as the data is definitely at your disposal, but as is apparent here, it's returning the whole city of San Francisco as a locality name?Brannon
D
4

As far as I know, you can't get Neighborhood data through the google maps API. You can try another web service like Urban Mapping's Neighborhood API: http://developer.urbanmapping.com/demo/ or Maponics (http://www.maponics.com/Neighborhood_Boundaries/neighborhood_boundaries.html). Urban Mapping's API contains methods for getting neighborhood by lat long and also various address elements.

Disordered answered 30/12, 2009 at 20:0 Comment(1)
This is not true. I have used Google Maps to get neighborhood names before.Fulbright
N
3
function getGeoInfo($street,$city,$state) {
    $url = "http://maps.googleapis.com/maps/api/geocode/json?address={$street}+{$city},+{$state}&sensor=false";
    $json_returned = file_get_contents($url);
    $data = json_decode($json_returned);
    return ($data);
}

Just as an example, of course you will have to urlEncode your variables and I would suggest using CuRL instead of the *file_get_contents* function.

If you var_dump the return you will see the neighborhood data and the structure to access it.

Necessaries answered 3/2, 2012 at 2:57 Comment(0)
H
2

An update - neighborhood data, when it is available, is now provided through Google's Geocoder via the new V3 API. Neighborhood is just another data type in the address_components array. More info is at code.google.com/apis/maps/documentation/geocoding/

Hungry answered 10/1, 2012 at 9:31 Comment(0)
H
0

Use the free service from http://www.maxmind.com/app/ip-location

You're never going to get it 100% accurate, but it should give you a head start.

There's also geotargeting in HTML5, but not all browsers support it yet and I'm unsure how to extract the user's geo location.

Hackery answered 9/12, 2009 at 2:6 Comment(2)
Great service, and advice, but it seems like this service speaks more to geolocating visitors to your site based on their IP. I am specifically looking to pull neighborhood data from some API (Google in this case), based on an address passed to the API from a form. i.e. in the above example the neighborhood should show as "The mission district" or "Mission".Brannon
Sorry, I misunderstood what you meant. I don't think Google Maps supports areas like what you're after.Hackery

© 2022 - 2024 — McMap. All rights reserved.