2012-12-22 20 views
8

क्या Google मानचित्र द्वारा गणना किए गए 2 पते के बीच दूरी रखने का कोई तरीका है? कैसे?पते के बीच दूरी

+3

स्टैक ओवरव्लो में आपका स्वागत है! किसी भी प्रकार की सहायता प्रदान करने के लिए आपको अधिक जानकारी प्रदान करनी होगी। आप किस प्रकार के डेटा से निपट रहे हैं? आपने क्या प्रयास किया है (विशेष रूप से, आपने किस प्रकार का कोड लिखा है)? –

उत्तर

2

आप इस Google Directions API उपयोग कर सकते हैं (जब आप एक मार्ग की दूरी हो) तो आपको पता तार या के रूप में एपीआई को प्रारंभ/समाप्ति स्थानों से गुजरती एक अनुरोध भेजें निर्देशांक और Google आपके लिए सभी पैर काम करेंगे।

मार्ग विभिन्न legs से बने हैं जो आपके द्वारा निर्दिष्ट कई बिंदुओं के आधार पर होते हैं। आपके परिदृश्य में (0 तरीके अंक) आपके पास केवल 1 पैर होना चाहिए जिसमें अनुमानित दूरी की संपत्ति होनी चाहिए।

17

यदि आपके पास केवल दो एड्रेस हैं तो GEOCODING द्वारा लैट लैन प्राप्त करने का प्रयास करें और फिर बीच में दूरी प्राप्त करने के कई तरीके हैं।

public int getDistance(string origin, string destination) 
{ 
    System.Threading.Thread.Sleep(1000); 
    int distance = 0; 
    //string from = origin.Text; 
    //string to = destination.Text; 
    string url = "http://maps.googleapis.com/maps/api/directions/json?origin=" + origin + "&destination=" + destination + "&sensor=false"; 
    string requesturl = url; 
    //string requesturl = @"http://maps.googleapis.com/maps/api/directions/json?origin=" + from + "&alternatives=false&units=imperial&destination=" + to + "&sensor=false"; 
    string content = fileGetContents(requesturl); 
    JObject o = JObject.Parse(content); 
    try 
    { 
     distance = (int)o.SelectToken("routes[0].legs[0].distance.value"); 
     return distance; 
    } 
    catch 
    { 
     return distance; 
    } 
    return distance; 
    //ResultingDistance.Text = distance; 
} 

    protected string fileGetContents(string fileName) 
    { 
     string sContents = string.Empty; 
     string me = string.Empty; 
     try 
     { 
      if (fileName.ToLower().IndexOf("http:") > -1) 
      { 
       System.Net.WebClient wc = new System.Net.WebClient(); 
       byte[] response = wc.DownloadData(fileName); 
       sContents = System.Text.Encoding.ASCII.GetString(response); 

      } 
      else 
      { 
       System.IO.StreamReader sr = new System.IO.StreamReader(fileName); 
       sContents = sr.ReadToEnd(); 
       sr.Close(); 
      } 
     } 
     catch { sContents = "unable to connect to server "; } 
     return sContents; 
    } 

या

आप गूगल और जरूरत के साथ चाहते हैं, तो गड़बड़ करने के लिए:

या

अगर आप न जियोकोडिंग की जरूरत है और एक सीएस समाधान यह कोशिश चाहते केवल एयर DISTANCE, इसे आजमाएं:

public decimal calcDistance(decimal latA, decimal longA, decimal latB, decimal longB) 
{ 

    double theDistance = (Math.Sin(DegreesToRadians(latA)) * 
      Math.Sin(DegreesToRadians(latB)) + 
      Math.Cos(DegreesToRadians(latA)) * 
      Math.Cos(DegreesToRadians(latB)) * 
      Math.Cos(DegreesToRadians(longA - longB))); 

    return Convert.ToDecimal((RadiansToDegrees(Math.Acos(theDistance)))) * 69.09M * 1.6093M; 
} 
+0

मुझे जॉब्जेक्ट पार्सर – user1901860

+0

कहां मिल सकता है और फ़ाइल गेटकंट्स फॉनक्शन क्या है? – user1901860

+0

मैंने JSON linq यहां डाउनलोड किया: http://james.newtonking.com/pages/json-net.aspx – user1901860

0

और मैंने यह किया: लेकिन यह एक खाली स्ट्रिंग लौटाता है। url = "http://maps.googleapis.com/maps/api/directions/json?origin=3320, rue de verdun, verdun & गंतव्य = 37 9, 1 9 एवेन्यू, ला ग्वाडेलोप, जी 0 एम 1 जी 0 & सेंसर = झूठा"

public string fileGetContents(string url) 
    { 
     string text = ""; 
     var webRequest = HttpWebRequest.Create(url); 
     IAsyncResult asyncResult = null; 
     asyncResult = webRequest.BeginGetResponse(
      state => 
      { 
       var response = webRequest.EndGetResponse(asyncResult); 
       using (var sr = new StreamReader(response.GetResponseStream())) 
       { 
        text = sr.ReadToEnd(); 
       } 
      }, null 
      ); 
     return text; 
    } 
संबंधित मुद्दे