2013-03-15 73 views
2

我一直在阅读相当多,但仍有点泥泞。我正在尝试构建一个在Google地点获取商家信息的应用,并显示地址,评论,图片,地理位置,描述等“详细信息”。请求详细信息与谷歌地点api

我不想执行搜索,因为我已经知道了企业名称和位置(用户将不会被搜索,但是观看导航到一个页面)

我一直在关注这一点:https://developers.google.com/maps/documentation/javascript/places#place_details_requests

和使用代码的形式在这里: Google Places API - Places detail request undefined

function initialize() { 
    var pyrmont = new google.maps.LatLng(50.458447,-3.509552); 

    map = new google.maps.Map(document.getElementById('map_canvas'), { 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
     center: pyrmont, 
     zoom: 15 
    }); 

    var request = { 
     location: pyrmont, 
     radius: 5000, 
     types: ['bar'] 
    }; 
    infowindow = new google.maps.InfoWindow(); 
    service = new google.maps.places.PlacesService(map); 
    service.search(request, callback); 
    } 

    function callback(results, status) { 
    if (status == google.maps.places.PlacesServiceStatus.OK) { 
     for (var i = 0; i < results.length; i++) { 
     createMarker(results[i]); 
     } 
    } 
    } 

    function createMarker(place) { 
    var placeLoc = place.geometry.location; 
    var marker = new google.maps.Marker({ 
     map: map, 
     position: place.geometry.location 
    }); 

    google.maps.event.addListener(marker, 'click', function() { 
     infowindow.setContent(place.name + "<br />" + place.formatted_address +"<br />" + place.website + "<br />" + place.rating + "<br />" + place.formatted_phone_number); 
     infowindow.open(map, this); 
    }); 
    } 

HTML:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script> 
</head> 
<body> 
    <div id="content"> 

     <div id="map_canvas"> 
      map 
     </div> 

    </div> 
</body> 

什么是执行GET请求,并把它在html针对特定的业务列表打印最简单的方法?

回答

1

我不能帮你的JavaScript代码。但我可以告诉你,你需要两次查看你的业务。在Places API中获取唯一的PlaceID后,再次在Details API中使用PlaceID。存储PlaceID,以便您再也不需要执行第一次查找。评论和时间可以随时间变化。

+0

这听起来很正确。 – vincentieo 2015-03-26 17:28:46

相关问题