Dot-Net

用於 Google Maps API 支持的 .NET 庫

  • April 30, 2020

我正在為 Google Maps 尋找一個 .NET 庫或包裝器,其中包含所有類型的響應作為 C# 類。

我希望能夠做類似的事情:

var url = "http://maps.googleapis.com/maps/api/geocode/json?address=Wellington&sensor=false";

//Utility functions would be ideal                  
string jsonResponse = GoogleMaps.GetJson(url);
string jsonResponse = GoogleMaps.GeocodeAddress("Wellington");

我希望能夠使用如下結果:

GeocodeResponse r = JsonConvert.DeserializeObject<GeocodeResponse>(jsonResponse);    //I am using Json.NET

if(r.status.Equals("OK"))
{
   DoSomethingWith(r.result.formatted_address);    //intellisense documentation for all the bits in the result would be great
}

這樣的事情存在嗎?

這有點像這些問題:

但是,答案不是我的意思,我不是在尋找拖放地圖控制項。

此 API 仍在開發中,但可能會為您提供您正在尋找的內容:

http://code.google.com/p/gmaps-api-net/

Google Maps API 的 .NET 包裝庫:

  1. GoogleAPI
  2. Google地圖

gmaps-api-net已過時(在此回答時) - Directions API 的最後一次更新是在 2016 年進行的。

GoogleApi的使用範例:

using GoogleApi.Entities.Common;
using GoogleApi.Entities.Maps.Directions.Request;
using GoogleApi.Entities.Maps.Directions.Response;

public void GetRoute()
{
   DirectionsRequest request = new DirectionsRequest();    

   request.Key = "AIzaSyAJgBs8LYok3rt15rZUg4aUxYIAYyFzNcw";

   request.Origin = new Location("Brasov");
   request.Destination = new Location("Merghindeal");

   var response = GoogleApi.GoogleMaps.Directions.Query(request);

   Console.WriteLine(response.Routes.First().Legs.First().DurationInTraffic);
   Console.WriteLine(response.Routes.First().Legs.First().Distance);
   Console.WriteLine(response.Routes.First().Legs.First().Steps);
}

引用自:https://stackoverflow.com/questions/5288194