2011-03-11 9 views
6

Google मानचित्र का उपयोग किए बिना विशेष शहर या सड़क या स्थान के लिए अक्षांश और देशांतर कैसे प्राप्त करें? उदाहरण के लिए उपयोगकर्ता नाम दर्ज शहर का नाम "चेन्नई" है और मुझे उस शहर के लिए केवल अक्षांश और देशांतर दिखाना होगा। यह कैसे करना है? विकिपीडिया पृष्ठGoogle मानचित्र का उपयोग किए बिना विशेष शहर या सड़क के लिए अक्षांश और देशांतर कैसे प्राप्त करें?

उत्तर

2

जांच Obtaining geographic coordinates जियोकोडिंग कहा जाता है, और एक अक्षांश और देशांतर के लिए एक जगह का नाम मिलान की आवश्यकता है।

आप या तो अपने ऐप में स्थान नाम/लैट-लॉन्स की एक ज्ञात सूची कोड कर सकते हैं, उन्हें रनटाइम पर पढ़ सकते हैं और आवश्यकता होने पर उनके माध्यम से खोज सकते हैं, या आप this one from Yahoo, या this one from Google जैसी ऑनलाइन जियोकोडिंग सेवा का उपयोग कर सकते हैं।

2

गूगल रिवर्स जियोकोडिंग प्रदान करता है - कृपया this लिंक के माध्यम से जाने

भी के लिए वेब सेवा नीचे दिए गए उदाहरण आप पैरामीटर में लंबे प्रदान की अक्षां का पता hte प्रतिक्रिया json में है देता है, लेकिन, this लिंक

अगर देखना आप एक्सएमएल में प्रतिक्रिया प्राप्त करना चाहते हैं तो here

1

मुझे एक ही समस्या थी .. अंततः मैंने इसे सर्वर की तरफ से लेट प्राप्त करके तय किया। This लिंक में जावा से लेट और लंबे समय तक नमूना कोड है। उम्मीद है कि यह किसी की मदद करता है।

private static final String GEOCODE_REQUEST_URL = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&"; 
    private static HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); 
    String strLatitude; 
    String strLongtitude; 
     public void getLongitudeLatitude(String address) { 
      try { 
       StringBuilder urlBuilder = new StringBuilder(GEOCODE_REQUEST_URL); 
       if (StringUtils.isNotBlank(address)) { 
        urlBuilder.append("&address=").append(URLEncoder.encode(address, "UTF-8")); 
       } 

       final GetMethod getMethod = new GetMethod(urlBuilder.toString()); 
       try { 
        httpClient.executeMethod(getMethod); 
        Reader reader = new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()); 

        int data = reader.read(); 
        char[] buffer = new char[1024]; 
        Writer writer = new StringWriter(); 
        while ((data = reader.read(buffer)) != -1) { 
          writer.write(buffer, 0, data); 
        } 

        String result = writer.toString(); 
        System.out.println(result.toString()); 

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
        DocumentBuilder db = dbf.newDocumentBuilder(); 
        InputSource is = new InputSource(); 
        is.setCharacterStream(new StringReader("<"+writer.toString().trim())); 
        Document doc = db.parse(is); 

        strLatitude = getXpathValue(doc, "//GeocodeResponse/result/geometry/location/lat/text()"); 
        System.out.println("Latitude:" + strLatitude); 

        strLongtitude = getXpathValue(doc,"//GeocodeResponse/result/geometry/location/lng/text()"); 
        System.out.println("Longitude:" + strLongtitude); 


       } finally { 
        getMethod.releaseConnection(); 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 

     private String getXpathValue(Document doc, String strXpath) throws XPathExpressionException { 
      XPath xPath = XPathFactory.newInstance().newXPath(); 
      XPathExpression expr = xPath.compile(strXpath); 
      String resultData = null; 
      Object result4 = expr.evaluate(doc, XPathConstants.NODESET); 
      NodeList nodes = (NodeList) result4; 
      for (int i = 0; i < nodes.getLength(); i++) { 
       resultData = nodes.item(i).getNodeValue(); 
      } 
      return resultData; 


    } 
संबंधित मुद्दे

 संबंधित मुद्दे