我正在创建一个使用google_places gem的应用,我想要搜索的是靠近所选位置的酒店和餐馆。 Google_places gem帮助了我很多,但它显示的内容类似于:
[#
@place_id =" ChIJl6wYnDyG_UYRLHo26ttMYf0",@ vicinity =" 48", @ lat = 54.1847303,@ lng = 18.432423, @viewport = {"东北" = GT; {" LAT" = GT; 54.1833813197085, " lng" => 18.1291523802915},"西南" => {" lat" => 54.1833813197085, " lng" => 18.12645441970849}},@ name =" Polando没有名字", @icon =" HTTPS://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png" ;,
我可以做些什么来正常显示名称,例如纬度?我只有:
@types = [" restaurant"," food"," point_of_interest"," establishment"],
<%= @ client.spots(@ trip.latitude,@ trip.longitude,:radius => 100, :types => ['酒店','睡觉'],详情:true)%
我在google_places gem存储库和google中找不到任何有用的东西,所以我决定在这里写一下。
谢谢!
答案 0 :(得分:1)
您提供的代码与您的标题相矛盾,因此我会尝试回答这两个问题:
在您的控制器中,如果您有@spots = @client.spots(@trip.latitude, @trip.longitude, :radius => 100, :types => ['hotel','sleep'], detail: true)
您应该能够在视图中迭代@spots
。
<% @spots.each do |spot| %>
<%= spot.name %>
<% end %>
如果有疑问,请点击#methods
(例如spot.methods
),这可以让您了解如何使用spot
或任何对象。
答案 1 :(得分:0)
有 Google API 的函数 getDetails(...),该函数返回有关某个地方的更多信息,并扩展了 nearbySearch()返回的信息。 ..)功能。
var SearchPlaces = {
GPMHotels: ['hotel']
, GPMFoodPlaces: ['restaurant']
, GPMShoppingPlaces: ['shopping_mall']
};
var service = new google.maps.places.PlacesService(GPMap);
function SearchGPMapServiceNearPlacesFn(service) {
function GetHTML(place) {
var distance = "";
if (place.geometry && place.geometry.location) {
var fromLatLng = new google.maps.LatLng(GPMapLocation.lat, GPMapLocation.lng);
distance = google.maps.geometry.spherical.computeDistanceBetween(fromLatLng, place.geometry.location);
distance = Math.ceil(distance).toLocaleString('@languaje');
}
var html = "* " + (distance ? distance + " m. " : "") + place.name + ". "
+ place.formatted_address + ". " +
(place.international_phone_number || "");
return html;
}
function GetPlaceDetails(place_id) {
if (!place_id) return;
service.getDetails({
placeId: place_id
}, function (place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
//-->> console.log({ fn: 'GetPlaceDetails', item: place });
$("#GPMNearSitesList").append($('<li>').html(GetHTML(place)));
}
});
}
service.nearbySearch({
location: GPMapLocation,
radius: GPMapOptions.searchRadiusList,
},
function (results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
GetPlaceDetails(results[i].place_id);
//-->>console.log({ fn: "SearchGPMapServiceNearPlacesFn", item: results[i] });
}
}
});
}
请参阅:https://developers.google.com/maps/documentation/javascript/examples/place-details