我正在使用Geocoder PHP库来获取地址的位置信息。我得到了所有数据,但我也需要区号。我哪里错了?
以下是我正在使用的代码:
$adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
$GeoJSON = new \Geocoder\Dumper\GeoJsonDumper;
$geocoder = new \Geocoder\Geocoder();
$lookfor = 'address goes here';
$geocoder->registerProvider(new \Geocoder\Provider\GoogleMapsProvider($adapter));
$result = $geocoder->geocode($lookfor);
echo $GeoJSON->dump($result);
这是当前的输出:
{"type":"Feature","geometry":{"type":"Point","coordinates":[-77.2899939,38.875973]},"properties":{"streetNumber":"93","streetName":"Flower Lane","zipcode":"00412","city":"Onkle","county":"Fur County","countyCode":"Fur COUNTY","region":"Virginia","regionCode":"VA","country":"United States","countryCode":"US"},"bounds":{"south":38.875973,"west":-77.2899939,"north":38.875973,"east":-77.2899939}}
答案 0 :(得分:2)
以前在Programmers.Stackexchange Is there an API for determining congressional districts
上已经回答了这个问题您无法从Geocoder库中提取您正在寻找的信息,因为它所关联的API都不提供该服务。获取位置信息后,您需要使用其他API才能获得地区。目前提供此功能的两个是SmartyStreets,它是付费服务,Sunlight Labs是免费的。
答案 1 :(得分:0)
此问题之前已在StackOverflow
上得到回答Geo Coding Address - get district of a certain address (Google API)
你想要的关键部分是'sublocality'