Asp.NET Google Direction Api

28 Ara

Google dan direction bilgisini liste çeklinde almak için başlangıç ve bitiş kordinatlarını vermeniz yeterlidir. Direction ı Adresten adrede şeklinde almak isterseniz Orgin ve Destination a kordinat yerine adres bilgisi göndermeniz yeterli olacaktır.

 

public List<DirectionRoute> direction(string lat1, string log1, string lat2, string log2) {
        XmlTextReader okuyucu = new XmlTextReader("http://maps.googleapis.com/maps/api/directions/xml?origin=" + lat1.Replace(',', '.') + "," + log1.Replace(',', '.') + "&destination=" + lat2.Replace(',', '.') + "," + log2.Replace(',', '.') + "&sensor=false");
        XmlDocument dokuman = new XmlDocument();
        dokuman.Load(okuyucu);

        XmlNodeList lat = dokuman.SelectNodes("/DirectionsResponse/route/leg/step/start_location/lat");
        XmlNodeList log = dokuman.SelectNodes("/DirectionsResponse/route/leg/step/start_location/lng");
        GooglePolyline NormalWay = new GooglePolyline(); NormalWay.Color = System.Drawing.Color.Black;
        NormalWay.Opacity = 1;
        List<DirectionRoute> routes = new List<DirectionRoute>();
        for (int i = 0; i < lat.Count; i++)
        {
            routes.Add(new DirectionRoute { lat = Convert.ToDouble(lat.Item(i).InnerText.Replace('.', ',')), log = Convert.ToDouble(log.Item(i).InnerText.Replace('.', ',')) });
        }
        return routes;
    }

    public class DirectionRoute
    {
        public double lat;
        public double log;
    }

Api ile birlikte farklı bilgilerde dönmektedir kordinat bilgisini aldığınız gibi diğer bilgileride alabilirsiniz.

Etiketler:, , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Yorum yapın

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Değiştir )

Twitter picture

You are commenting using your Twitter account. Log Out / Değiştir )

Facebook photo

You are commenting using your Facebook account. Log Out / Değiştir )

Connecting to %s

Follow

Get every new post delivered to your Inbox.