Returning neighborhood based on address with Googl

2019-06-28 03:29发布

问题:

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.

回答1:

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.



回答2:

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.



回答3:

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/



回答4:

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.