obito1406 obito1406 - 14 days ago 7
C# Question

google maps API for C#

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 app all i need to know if i can use the google maps API on C#.
This is the one i will like to use

Ive look for it on many places but all i could find was alternatives to using Gmaps but thats not what i want.

┬┐It is possible to use it?

Answer

Sure you can.

There is no dedicated library I'm aware of. But you can just send HTTP-Requests to the google maps API and then work with the results. You could use WebRequest to forge requests to the google api.

This would be a simple example. You would have to build up the GET parameters eg. origin=...&destination=...&key=YOUR_API_KEY + parse the JSON response to do something with it.

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();