Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning neighborhood based on address with Google geocoder/API

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.

like image 759
dnyce Avatar asked Jan 23 '23 21:01

dnyce


2 Answers

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.

like image 132
Sweet Lew Avatar answered Jan 25 '23 11:01

Sweet Lew


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.

like image 42
digdan78 Avatar answered Jan 25 '23 10:01

digdan78