Java get Google address

Source: Internet
Author: User
Private string getaddr (string latitude, string longbench) {string ADDR = ""; // can it also be a http://maps.google.cn/maps/geo? Output = CSV & Key = abcdef & Q = % s, % s, but the parsed address is an English address // key. You can write a key = ABC // output = CSV, it can also be XML or JSON, but the data returned by using CSV is the most concise and convenient to parse string url = string. format ("http://ditu.google.cn/maps/geo? Output = CSV & Key = abcdef & Q = % s, % s ", latitude, longpolling); Url myurl = NULL; urlconnection httpsconn = NULL; try {myurl = new URL (URL);} catch (malformedurlexception e) {e. printstacktrace (); return NULL;} Try {httpsconn = (urlconnection) myurl. openconnection (); If (httpsconn! = NULL) {inputstreamreader insr = new inputstreamreader (httpsconn. getinputstream (), "UTF-8"); bufferedreader BR = new bufferedreader (insr); string data = NULL; If (Data = BR. readline ())! = NULL) {// system. out. println (data); string [] retlist = data. split (","); If (retlist. length> 2 & <200 ". equals (retlist [0]) {ADDR = retlist [2]; ADDR = ADDR. replace ("\" "," ") ;}else {ADDR =" ";}} insr. close () ;}} catch (ioexception e) {e. printstacktrace (); return NULL;} return ADDR ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.