google maps API for C#

后端 未结 3 1750
终归单人心
终归单人心 2020-11-28 14:39

im really new in to using APIs so after looking on google maps Api page im not sure if there are APIs designed to be used for C#. I dont need a google maps to be show on my

3条回答
  •  Happy的楠姐
    2020-11-28 15:15

    As mentioned in the other respose(s), you can make HTTP requests and use the JSON response.

    If you want a .NET library that makes your life easier by abstracting the query/response you can use one of these .NET wrapper libraries for the Google Maps API :

    1. GoogleApi
    2. google-maps

    gmaps-api-net is outdated (at this time of answering) - the last update for the Directions API was made in 2016.

    Usage example for 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);
    }
    

提交回复
热议问题