2016-12-06 55 views
0

我一直試圖通過谷歌地圖在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 
+0

我相信你需要使用谷歌的地方搜索API此。看看文檔https://developers.google.com/places/web-service/search – Kushal

+0

有沒有什麼辦法可以將goople的地方api整合到geocoder和googlemaps4rails? –

+0

閱讀答案[這個問題](http://stackoverflow.com/questions/26073847/using-google-places-api-in-rails-app) –

回答

0

您需要提供的座標更準確。檢查enterprice的經度和緯度。

例如,不準確會

enterprise.latitude 
# => 41 
enterprise.longitude 
# => -87 

,準確的是

enterprise.latitude 
# => 41.850033 
enterprise.longitude 
# => -87.6500523 
+0

我把它作爲第二,也許我需要的地方API –

+0

請詳細描述你想要什麼?你想提供座標並獲得有關地點的信息嗎? –

+0

基本上我需要得到確切的地方,而不是在街道上,我想要像大學,餐館,學校等地方。我無法得到它,它只能設法得到城市,也許這個地方的街道,但不確切的地方,我顯示它 –

1

顯然,我需要添加這樣的事情在我的應用程序,我想在我的javascript代碼,但是我沒有得到任何改變

"results" : [ 
    { 
     "place_id" : "MY_KEY_API", 
     "scope" : "GOOGLE", 
     "alt_ids" : [ 
     { 
      "place_id" : "MY_KEY_API", 
      "scope" : "APP", 
     } 
     ] 
0

我假設你需要更具體的查詢谷歌地圖...

因此,當使用Google Places API時,每個PlaceResult對象都可以從各種參數進行查詢......您需要的是指定types參數。

從上面的網址複製和粘貼...

types An array of types for this place (e.g., ["political", "locality"] or ["restaurant", "lodging"]). 

試試看吧.. :)

+0

嗨Milind!我沒有使用Google地方信息,只是使用Geocoder和GoogleMaps4Rails寶石,當我回到家時,我注意到了您的建議! –

相關問題