2016-06-24 52 views
0

我正在使用Google geocoing(geolocation,places)api的網站上工作。我前幾天添加了這些API。它工作正常。但後來我發現它現在不再工作了。總是有例外。一些檢查後,我發現這一點:Google地理編碼API無法使用新密鑰?

http://googlegeodevelopers.blogspot.com.au/2016/06/building-for-scale-updates-to-google.html

這是因爲他們不再支持無鑰匙進入(不包括API密鑰的任何請求)。

所以,我按照說明,啓用API,創建密鑰,添加到調用URL的關鍵,等待了大約1天,但它仍然無法正常工作。以下是其中一個代碼:

public static MapLocation GoogleGeoCode(string address) 
{ 
    MapLocation ret = null; 

    try 
    { 
     var requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false&key=***", Uri.EscapeDataString(address)); 

     var request = WebRequest.Create(requestUri); 
     var response = request.GetResponse(); 
     var xdoc = XDocument.Load(response.GetResponseStream()); 

     var result = xdoc.Element("GeocodeResponse").Element("result"); 
     var locationElement = result.Element("geometry").Element("location"); 
     var lat = locationElement.Element("lat"); 
     var lng = locationElement.Element("lng"); 

     ret = new MapLocation 
     { 
      Lat = double.Parse(lat.Value) 
      , 
      Lng = double.Parse(lng.Value) 
     }; 
    } 
    catch (Exception ex) 
    { 
     Debug.WriteLine(ex.ToString()); 
     ret = null; 
    } 

    return ret; 
} 

我在我的DEV機器上嘗試了服務器密鑰和瀏覽器密鑰。在瀏覽器鍵中,我沒有設置任何引用。在服務器密鑰中,我沒有填寫「接受來自這些服務器IP地址的請求」選項中的任何內容。

任何人都知道我在做什麼錯?或者,任何人都可以使用新密鑰來調用API?

謝謝

+0

你會得到什麼確切的答覆? (請編輯它的問題) – stuartd

+0

事實證明,它現在需要https。一旦改爲https,它將再次與服務器密鑰一起工作。 – urlreader

回答

0

事實證明,它現在需要https。一旦改爲https,它將再次與服務器密鑰一起工作。

相關問題