Googleapi in Visualstudio

Asked

Viewed 32 times

1

I’m trying to implement on top of a ready-made class that I was sent that uses Googleapi, but I can’t possibly add the reference to the project via Nuget. Do you know where I can download it? Follow the code:

using System.Collections.Generic;

using System.IO;

using System.Net;

using GoogleAPI.Maps.Model; // Esta daqui

using GoogleAPI.Maps.Model.Geocoding; // Esta daqui também

using Newtonsoft.Json;

namespace CepApp

{
    public class AddressUtil

    {

        public class Location
        {
            public double lat { get; set; }
            public double lng { get; set; }
        }

        public class Geometry
        {
            public Bounds bounds { get; set; }
            public Location location { get; set; }
            public string location_type { get; set; }
            public Viewport viewport { get; set; }
        }

        public class Result
        {
            public List<AddressComponent> address_components { get; set; }
            public string formatted_address { get; set; }
            public Geometry geometry { get; set; }
            public string place_id { get; set; }
            public List<string> types { get; set; }
        }


        public class RootObject
        {
            public List<Result> results { get; set; }
            public string status { get; set; }
        }

        public static RootObject GetLatLongByAddress(string address)
        {
            var root = new RootObject();

            var url =
                string.Format(
                    "http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=true_or_false", address);
            var req = (HttpWebRequest)WebRequest.Create(url);

            var res = (HttpWebResponse)req.GetResponse();

            using (var streamreader = new StreamReader(res.GetResponseStream()))
            {
                var result = streamreader.ReadToEnd();

                if (!string.IsNullOrWhiteSpace(result))
                {
                    root = JsonConvert.DeserializeObject<RootObject>(result);
                }
            }
            return root;
        }
    }
}

reinforcing: The class was already implemented in another project, but I can’t add to the reference to my.

Thank you!

  • tried to grab the other project’s api and add the reference to this ?

  • The guy traveled, sent me the class by email, then it gets hard kkk

1 answer

0

Use that Nuget here:

Install-Package Google.Maps.Client

However the Viewport there is something specific App, I took it from the code.

https://gist.github.com/thiagoloureiro/02a2fd3f162dcb026d8b7a318d8f5dd6

using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Net;
using Velyo.Google.Services.Models;

namespace CepApp

{
    public class AddressUtil

    {
        public class Location
        {
            public double lat { get; set; }
            public double lng { get; set; }
        }

        public class Geometry
        {
            public Bounds bounds { get; set; }
            public Location location { get; set; }
            public string location_type { get; set; }
            // public Viewport viewport { get; set; }
        }

        public class Result
        {
            public List<AddressComponent> address_components { get; set; }
            public string formatted_address { get; set; }
            public Geometry geometry { get; set; }
            public string place_id { get; set; }
            public List<string> types { get; set; }
        }

        public class RootObject
        {
            public List<Result> results { get; set; }
            public string status { get; set; }
        }

        public static RootObject GetLatLongByAddress(string address)
        {
            var root = new RootObject();

            var url =
                string.Format(
                    "http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=true_or_false", address);
            var req = (HttpWebRequest)WebRequest.Create(url);

            var res = (HttpWebResponse)req.GetResponse();

            using (var streamreader = new StreamReader(res.GetResponseStream()))
            {
                var result = streamreader.ReadToEnd();

                if (!string.IsNullOrWhiteSpace(result))
                {
                    root = JsonConvert.DeserializeObject<RootObject>(result);
                }
            }
            return root;
        }
    }
}

https://msdn.microsoft.com/en-us/library/windows/desktop/bb324012(v=vs.85). aspx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.