Google Maps API for C #

im really new to using the api, so by looking at google api maps i'm not sure if there are api intended for use in c #. I donโ€™t need google maps to display in my application, all I need to know is if I can use google maps API in C #. This is the one I will like

I look for it in many places, but all I could find was an alternative to using Gmaps, but that is not what I want.

ยฟCan it be used?

+5
source share
1 answer

1. Create your own Google Maps API requests

You can simply send HTTP requests to google map APIs and then work with the results. You can use WebRequest to fit google api requests. For this you need the Maps API Key .


You will need to create GET parameters, for example. origin=...&destination=...&key=YOUR_API_KEY + parse the JSON response to do something with it.

The Google Maps Api documentation (under the web services API) lists request parameters and answers for an example.

 string url = @"https://maps.googleapis.com/maps/api/directions/json?origin=75+9th+Ave+New+York,+NY&destination=MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073&key=YOUR_API_KEY"; WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream data = response.GetResponseStream(); StreamReader reader = new StreamReader(data); // json-formatted string from maps api string responseFromServer = reader.ReadToEnd(); response.Close(); 

JSON response will look something like this (from the Directions API )

 { "geocoded_waypoints" : [ { "geocoder_status" : "OK", "place_id" : "ChIJRVY_etDX3IARGYLVpoq7f68", "types" : [ "bus_station", "transit_station", "point_of_interest", "establishment" ] }, { "geocoder_status" : "OK", "partial_match" : true, "place_id" : "ChIJp2Mn4E2-woARQS2FILlxUzk", "types" : [ "route" ] } ], "routes" : [ { "bounds" : { "northeast" : { "lat" : 34.1330949, "lng" : -117.9143879 }, "southwest" : { "lat" : 33.8068768, "lng" : -118.3527671 } }, "copyrights" : "Map data ยฉ2016 Google", "legs" : [ { "distance" : { "text" : "35.9 mi", "value" : 57824 }, "duration" : { "text" : "51 mins", "value" : 3062 }, "end_address" : "Universal Studios Blvd, Los Angeles, CA 90068, USA", "end_location" : { "lat" : 34.1330949, "lng" : -118.3524442 }, "start_address" : "Disneyland (Harbor Blvd.), S Harbor Blvd, Anaheim, CA 92802, USA", "start_location" : { "lat" : 33.8098177, "lng" : -117.9154353 }, ... Additional results truncated in this example[] ...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EjGgDxCaC`BuJdFkFtCgCnBuClD_HdMqEzHcBpB_C|BuEzCmPlIuE| B_EtDeBhCgAdCw@rCi @| DSfECrCAdCS~Di@jDYhA _AlC{AxCcL`U{GvM_DjFkBzBsB` BqDhBaEfAsTvEmEr@iCr @ qDrAiFnCcEzCaE~D_@JmFdGQDwBvCeErEoD |BcFjC}DbEuD~D`@ Zr@h @ ?d@Wr @}@vAgCbEaHfMqA` Cy@dAg @bAO`@ gCi@w @W" }, "summary" : "I-5 N and US-101 N", "warnings" : [], "waypoint_order" : [] } ], "status" : "OK" } 

2 .... or use a dedicated library

  • gmaps-api-net (github) offers an api interface for Google Maps. You can get it through nuget. I have not tested it, but it looks very easy to use.
+5
source

Source: https://habr.com/ru/post/1239821/


All Articles