javascript - 如何使用google api获取电话号码

标签 javascript ajax html google-maps

这是我的代码

function show(placelanlat,names) 
{   
var placenames=names;
var planlat=placelanlat;
var newStr= planlat.replace(/[(\)]/g,'');
var aCars = newStr.split(',');
var infowindow = new google.maps.InfoWindow();
var marker;
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(12.588,-83.667);
var myOptions = {
  zoom: 8,
  center: latlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvass"), myOptions);
var input = newStr;
var latlngStr = input.split(",",2);
var lat = parseFloat(latlngStr[0]);
var lng = parseFloat(latlngStr[1]);
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {  
if (status == google.maps.GeocoderStatus.OK) {
  if (results[1]) {
    map.setZoom(11);
    marker = new google.maps.Marker({
      position: latlng,
      map: map,
      icon: 'images/images.png'
    });
    infowindow.setContent(placenames+"</br>"+results[0].formatted_address+"</br>");
    infowindow.open(map, marker);
    }
    }
  else {
  alert("Geocoder failed due to: " + status);
  }
   });
 return false; // MANDATORY!
  } 

如果我设置

infowindow.setContent(placenames+"</br>"
                      +results[0].formatted_address
                      +"</br>"+results[0].formatted_phone);
results[0].formatted_phone ->

这显示为空。为什么? 我想更改以获取地点电话号码的位置。 示例:http://www.google.com/maps?source=uds&daddr=India,++%28India%29+@20.593684,78.96288&saddr=37.781287,-122.395575

最佳答案

如果你使用 The Google Places API (Experimental) 然后按照这些步骤

启动地点搜索请求需要某些参数

key (required) — Your application's API key. 
location (required) —  This must be specified as latitude,longitude.
radius (required) — The distance (in meters) within which to return Place results.
sensor (required) — This value must be either true or false.

结果数组中的每个结果可能包含

reference contains a unique token that you can use to retrieve additional information about this place in a Place Details request. You can store this token and use it at any time in future to refresh cached data about this Place, but the same token is not guaranteed to be returned for any given Place across different searches.

  • 地点搜索请求获得引用后,您可以通过启动来请求有关特定机构或兴趣点的更多详细信息地点详情请求

    Place Details 请求会返回有关指定地点的更全面的信息,例如其完整地址、电话号码、用户评分等。 地点详情请求是以下形式的 HTTP 网址:

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

发起搜索请求需要某些参数。

key (required) — Your application's API key.
reference (required) — A textual identifier that uniquely identifies a place, returned from a Place search request.
sensor (required) —  This value must be either true or false.
  • Place Details 的输出包含

    formatted_phone_numberinternational_phone_number

希望对你有帮助

关于javascript - 如何使用google api获取电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8722517/

相关文章:

javascript - 以Redux状态: reflection of API object vs.简化形式状态存储数据

javascript - Javascript 或 JQuery 中的 "!!"是什么?

Javascript - 对对象执行深度搜索

javascript - 将 ajax 错误从 python 返回到 jquery

javascript - Apollo 查询返回错误 "Expected String, found String"

javascript - 预检响应无效(重定向),浏览器继续使用 OPTION 方法

javascript - 从 PHP 文件发回消息

javascript - 如何增加我的推特提要的宽度

html - CSS 不能选择div,但是可以选择h1

java - 从数据库中检索数据并用单选按钮显示它,单选按钮包含 struts 1.2 中的数据值