如何从谷歌位置/地图获得更多结果

How do I get more results from Google Places / Maps

本文关键字:结果 地图 谷歌 位置      更新时间:2023-09-26

我正在使用谷歌地图,我正在尝试API的地方,但有些事情让我想知道。。。

如果你加载maps.google.com去吉隆坡,然后在搜索框中键入"食物",你会在地图上看到数百家餐馆。我想把这些放到我自己的地图上。

使用Places API,我几乎复制了他们的示例代码:

function initialize() {
    var plat = 3.15;
    var plong = 101.7;
    var ppos = new google.maps.LatLng(plat, plong);
    var mapOptions = {
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        draggable: false,
        zoom: 10,
        center: ppos
    };
    map = new google.maps.Map(document.getElementById("mapcanvas"), mapOptions);
    var request = {
        location: ppos,
        radius: '10000'
    };
    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,
        icon: place.icon
    });
    google.maps.event.addListener(marker, 'click', function () {
        infowindow.setContent("<b>" + place.name + "</b><br/>" + place.vicinity);
        infowindow.open(map, this);
    });
}

当我执行这个代码时,我确实会得到结果,但只有极少数,也只有像一些商场和博物馆这样的主要地点。那么,我如何获得我在谷歌自己的地图上看到的所有漂亮的数据呢?

因此出现了许多问题:Inodesia中的分类被破坏,因此使用关键字来解决问题,如:

var request= { 
  location: ppos, 
  radius: 10000, 
  keyword: 'restaurant' }

关键字采用字符串而不是数组,radius采用数字而不是字符串。您可以在此处查看请求类型的摘要:http://code.google.com/apis/maps/documentation/javascript/reference.html#PlaceSearchRequest