了解与网页配合使用的Google Places API [英] understand the google places api for using with a webpage

查看:95
本文介绍了了解与网页配合使用的Google Places API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我仔细阅读了文档,但是我仍然不清楚它是如何工作的。如果我想搜索一个地方,我应该使用HTTP get请求返回json数据。如何使用JavaScript执行此操作?文档只是向我展示了如何构造HTTP请求

OK so I rad through the documentation however I still don't understand exactly how it works. If I want to search for a place I am supposed to use an HTTP get request to return json data. How do I do this using JavaScript? The documentation just shows me how to structure the HTTP request like so

https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters

但是我该如何发送此请求?为我指点教程或其他内容会很棒。

But how do I then send this request? Pointing me to a tutorial or something would be great.

推荐答案

地方信息库 完成所有工作。您只需发送 字段 要求,然后显示 地方详细信息结果

以下代码摘自文档,向您显示在何处添加以实现您的首选项。

The following code is taken from the documentation to show you where to add to it to implement your preferences.

var map;
var service;
var infowindow;

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

  map = new google.maps.Map(document.getElementById('map'), {
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: pyrmont,
      zoom: 15
    });
 //Here you add the fields you require for request for PlacesService() 
  var request = {
    location: pyrmont,
    radius: '500',
    types: ['store']
  };

  service = new google.maps.places.PlacesService(map);
  service.nearbySearch(request, callback);
}
  //Here you display the Place Details Results
function callback(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      var place = results[i];
      createMarker(results[i]);
    }
  }
}

这篇关于了解与网页配合使用的Google Places API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆