这是我的代码
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)
然后按照这些步骤
- 首先获取一个API key
现在使用放置搜索请求
Place Search 请求是以下形式的 HTTP URL:
https://maps.googleapis.com/maps/api/place/search/output?parameters
启动地点搜索请求需要某些参数
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_number
和international_phone_number
。
希望对你有帮助
关于javascript - 如何使用google api获取电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8722517/