我一直試圖通過谷歌地圖在Rails中獲得特定位置,因爲當我嘗試獲得餐廳,大學時,我無法獲得!我只得到這個城市,或者這個國家,也許這條街,但不是那個地方。如何通過谷歌地圖獲得軌道上的特定位置
觀點:
<div style='width: 100%;' class="border">
<div id="map" style='width: 100%; height: 260px;'></div>
</div>
<script src="//maps.google.com/maps/api/js?key=AIzaSyAqkiGaIZh9q6DPUabw9E1rEqIQ-9X5amI"></script>
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
<script src='//cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js' type='text/javascript'></script> <!-- only if you need custom infoboxes -->
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%= raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
handler.getMap().setZoom(15);
});
</script>
控制器,動作顯示:
def show
@enterprise = Enterprise.find(params[:id])
@hash = Gmaps4rails.build_markers(@enterprise) do |enterprise, marker|
marker.lat enterprise.latitude
marker.lng enterprise.longitude
end
end
我相信你需要使用谷歌的地方搜索API此。看看文檔https://developers.google.com/places/web-service/search – Kushal
有沒有什麼辦法可以將goople的地方api整合到geocoder和googlemaps4rails? –
閱讀答案[這個問題](http://stackoverflow.com/questions/26073847/using-google-places-api-in-rails-app) –