简体   繁体   中英

c#:getting longitude and latitude from address

I am designing a website which converts and stores longitude and latitude of the entered address.iused google geocoding api for this purpose and the code I used to convert address to longitude and latitude is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Geocoding.Google;
using Geocoding;
public partial class test3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        IGeocoder geocoder = new GoogleGeocoder() {  };
        Address[] addresses = geocoder.Geocode(TextBox1.Text).ToArray();
        foreach (Address adrs in addresses)
        {
            Response.Write("address:"+adrs);
        }
    }
}

And for the input Delhi,India instead of getting the longitude and latitude values i am getting more specific address again

address:New Delhi, Delhi, India

please somebody who used google api before help me to modify my code.

You can use Coordinates

Replace This:

Response.Write("address:"+adrs);

With This:

Response.Write("address:"+adrs.Coordinates);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM