【问题标题】:how to get phone number using google api如何使用google api获取电话号码
【发布时间】:2012-01-04 05:42:00
【问题描述】:

这是我的代码

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

【问题讨论】:

    标签: javascript ajax html google-maps


    【解决方案1】:

    如果你使用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 包含一个唯一令牌,您可以使用该令牌在“地点详情”请求中检索有关此地点的其他信息。 您可以存储此令牌并在将来随时使用它来刷新 关于此地点的缓存数据,但不保证相同的令牌 在不同搜索中为任何给定地点返回。

    • 地点搜索请求获得reference后,您可以通过发起地点详细信息请求来请求有关特定场所或兴趣点的更多详细信息。

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

      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

    希望对你有帮助。

    【讨论】:

    • 我已经更新了我的答案。注意:您必须为此需要API key
    • ya.i 有地名和地名和 API 密钥的 lan &lat
    • ya.i 有地名和地名的 lan &lat 和 API 密钥。 var 地名=名称; var latlng = new google.maps.LatLng(lat, lng); API 密钥 = 我的 API 密钥。如何放入我上面的代码中。
    • 我用过:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    相关资源
    最近更新 更多