如何使用谷歌API获取电话号码 [英] how to get phone number using google api
问题描述
这是我的代码
$ b $ pre $ function show(placelanlat,names)
{
var placenames =名称;
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);
}
});
返回false; //强制!
}
如果我设置了
infowindow.setContent(placenames +< / br>
+ results [0] .formatted_address
+< / br>+ results [0 ] .formatted_phone);
结果[0] .formatted_phone - >
这显示empty.why?
,我想要更改地点电话号码。
例如:http://www.google.com/maps?source = uds& daddr =印度,++%28印度%29 + @ 20.593684,78.96288& saddr = 37.781287,-122.395575
nofollow> Google Places API(实验性)
,然后按照以下步骤操作:
- 首先获取 API密钥
-
现在使用放置搜索请求
地点搜索请求是以下格式的HTTP网址:
https://maps.googleapis.com/maps/api/place/search/output?parameters
启动地方搜索请求需要某些参数
key(必需) - 您的应用程序的API密钥。
位置(必填) - 必须指定为纬度,经度。
半径(必填) - 要返回的距离(以米为单位)放置结果。
传感器(必需) - 此值必须为真或假。
结果数组中的每个结果可能包含
< blockquote>
引用包含一个唯一标记,您可以使用该标记在地方详细信息请求中检索有关此地点的其他信息。
您可以存储此令牌并在将来随时使用它来刷新有关此Place的
缓存数据,但不能保证同一令牌在任何给定Place的不同搜索中返回
。
-
获得
参考$ c $您可以通过发起地点详细信息请求来请求有关特定商户或兴趣点的更多详情。
地点详细信息请求会返回有关指定地点的更全面信息,例如完整地址,电话号码,用户评分等。
地点详细信息请求是以下格式的HTTP URL:
https: //maps.googleapis.com/maps/api/place/details/output?parameters
某些参数需要启动一个搜索ch请求。
key(必需) - 您的应用程序的API密钥。
reference(必填) - 一个文本标识符,用于唯一标识从地方搜索请求返回的地点。
传感器(必需) - 此值必须为真或假。
-
地点详细信息的输出包含
formatted_phone_number
和international_phone_number
。
希望它能帮助你。
this is my code
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!
}
if i set
infowindow.setContent(placenames+"</br>"
+results[0].formatted_address
+"</br>"+results[0].formatted_phone);
results[0].formatted_phone ->
this is showing empty.why? where i want to change to get place phone number. example:http://www.google.com/maps?source=uds&daddr=India,++%28India%29+@20.593684,78.96288&saddr=37.781287,-122.395575
if you use The Google Places API (Experimental)
then follow these steps
- first get an API key
now use Place Search Requests
A Place Search request is an HTTP URL of the following form:
https://maps.googleapis.com/maps/api/place/search/output?parameters
Certain parameters are required to initiate a Place Search request
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.
Each result within the results array may contain
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.
Once you have a
reference
from a Place Search request, you can request more details about a particular establishment or point of interest by initiating a Place Details request.A Place Details request returns more comprehensive information about the indicated place such as its complete address, phone number, user rating, etc. A Place Details request is an HTTP URL of the following form:
https://maps.googleapis.com/maps/api/place/details/output?parameters
Certain parameters are required to initiate a search request.
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.
output of Place Details contains
formatted_phone_number
andinternational_phone_number
.
Hope it would helps u.
这篇关于如何使用谷歌API获取电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!