2012-01-04 94 views
3

,这是我的代码如何使用谷歌API

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 -> 

这显示empty.why得到的电话号码? 我想要更改地点电话号码。 例如:http://www.google.com/maps源= UDS & DADDR =印度,++%28India%29 + @ 20.593684,78.96288 & SADDR = 37.781287,-122.395575

回答

3

如果使用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,您可以通过启动位置详情请求请求有关特定场所或兴趣点的详细信息。

    地方详情请求返回有关指定位置更全面的信息,例如其完整地址,电话号码,用户评价等 地方详情请求是采用以下形式的HTTP网址:

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

需要某些参数来启动搜索请求。Place详细的

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. 
  • 输出包含

    formatted_phone_numberinternational_phone_number

希望它能帮助你。

+0

您看到此链接。 http://code.google.com/apis/maps/documentation/places/ – SANR1103219 2012-01-04 06:17:31

+0

我已经更新了我的答案。注意:您必须为那个 – diEcho 2012-01-04 06:54:16

+0

ya.i需要'API密钥'。地名和地址名称以及API密钥 – SANR1103219 2012-01-04 06:59:32