2012-01-04 170 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