从Symfony Ivory Bundle中的Google places API获取坐标

时间:2016-02-10 10:59:14

标签: google-places

我在Symfony项目中,我必须为用户分配一个地址。然后我必须在地图上显示他们的位置。 我使用Ivory Google Maps Bundle。标记与coordonates合作。 因此,我认为最好的方法是使用Google商家信息并获取 coordonates。 然后将其分配给标记。

问题是:如何从Google Places API获取坐标并将其与doctrine一起存储?

1 个答案:

答案 0 :(得分:0)

您的捆绑包可以查询The Google Maps Geocoding API,其中提供了有关坐标的地方的信息。

// Requests the ivory google map geocoder service
$geocoder = $this->get('ivory_google_map.geocoder');

// Geocode an address
$response = $geocoder->geocode('YOUR_ADDRESS_HERE');

// Get the result corresponding to your address
foreach($response->getResults() as $result) {
    var_dump($result->getGeometry()->getLocation());
}

这是full doc