GoogleApi
1.0.0
無縫 Google Api 整合。
Google 地圖、地點、道路、搜尋和翻譯。
請隨意貢獻、提出問題和回報問題。我通常回覆速度很快(24-48 小時)。
您需要額外的 .Net 框架支援嗎?
新增內容:版本 5.0.0 包含路線 Api(方向和矩陣)、Ariel View Api 和位址驗證 Api。
可以透過使用單獨的 Facede 實作或透過相依性注入單獨的 api 來使用該函式庫。
每個 api 實作都包含一個請求和一個回應。請求具有反映支援的參數的屬性,回應表示傳回的 json 的物件模型。
其他一些值得注意的成員。
var uri = request . GetUri ( ) ; // Gets the full request uri, including query parameters.
var params = request . GetQUeryStringParameters ( ) ; // Gets a list of all the added parameters.
response . RawJson // The raw json returned by Google.
response . RawQueryString // The querystring sent to Google when invoking the request.
每個 api 都有一個通用的外觀操作來執行請求並回傳回應。
下面的範例僅填入請求、呼叫外觀操作並接收傳回的回應。
TRequest request = new TRequest ( ) ;
TResponse response = await { Api } . [ { SubGroup } ] . { Action } . QueryAsync < TRequest , TResponse > ( request ) ;
請參閱下文,了解支援的 Api 和操作的完整清單。
如果首選將 api 作為依賴項注入,請在啟動期間註冊服務,如下所示。
services
. AddGoogleApiClients ( ) ;
然後,根據需要將各個 Api 注入建構函式中
public class MyClass
{
private Api api ;
public MyClass ( Api api )
{
this . api = api
}
}
請參閱下文,了解支援的 Api 和操作的完整清單。
如果需要WebProxy
,請在註冊 GoogleApi 依賴項或使用 Facade 之前設定靜態屬性HttpClientFactory.Proxy
。
支持以下 api。
GoogleMaps.Directions
)GoogleMaps.DistanceMatrix
)GoogleMaps.Elevation
)GoogleMaps.Geocode.PlaceGeocode
)GoogleMaps.Geocode.AddressGeocode
)GoogleMaps.Geocode.LocationGeocode
)GoogleMaps.Geocode.PlusCodeGeocode
)GoogleMaps.Geolocation
)GoogleMaps.Roads.NearestRoads
)GoogleMaps.Roads.SnapToRoad
)GoogleMaps.Roads.SpeedLimits
)GoogleMaps.Routes.Directions
)GoogleMaps.Routes.Matrix
)GoogleMaps.AddressValidation
)GoogleMaps.AerialView.GetVideo
)GoogleMaps.AerialView.RenderVideo
) GooglePlaces.Search.FindSearch
)GooglePlaces.Search.NearBySearch
)GooglePlaces.Search.TextSearch
)GooglePlaces.Details
)GooglePlaces.Photos
)GooglePlaces.AutoComplete
)GooglePlaces.QueryAutoComplete
) GoogleSearch.WebSearch
)GoogleSearch.ImageSearch
)GoogleSearch.VideoSearch.Channels
)GoogleSearch.VideoSearch.Playlists
)GoogleSearch.VideoSearch.Vidoes
) GoogleTranslate.Detect
)GoogleTranslate.Languages
)GoogleTranslate.Translate
) 運行測試套件很簡單。
測試項目將與您的 Google 訂閱(免費或付費)相關的設定儲存在application.default.json
中。
最重要的是ApiKey
,用於識別 Google 訂閱。
{
"ApiKey" : " " ,
"SearchEngineId" : " " ,
}
有關生成密鑰的更多資訊可以在這裡找到:https://console.developers.google.com/