A web-based API that uses the high-D API to convert addresses to latitude and longitude

Source: Internet
Author: User

Import Com.fengyunhe.helper.http.httpclienthelper;import Java.io.ioexception;import Java.io.unsupportedencodingexception;import Java.net.urlencoder;import Java.util.arrays;import Java.util.regex.matcher;import java.util.regex.pattern;/** * Created by Yan on 2015/9/28. */public class Testgaode {private static String API = "Http://restapi.amap.com/v3/geocode/geo?key=<key>&s=rs    V3&address=<address> ";    private static String KEY = "aa4a48297242d22d2b3fd6eddfe62217";    private static pattern pattern = Pattern.compile ("\" location\ ": \" (\\d+\\.\\d+), (\\d+\\.\\d+) \ "");    static {init ();        } private static void Init () {System.out.println ("German Map Tool class initialization");        System.out.println ("API: {}" +api);        System.out.println ("key: {}" +key);    API = Api.replaceall ("<key>", key); } public static double[] Addresstogps (string address) throws IOException {try {String Requesturl = Api.replaceall ("<address>", Urlencoder.enCode (address, "UTF-8"));            SYSTEM.OUT.PRINTLN ("Request address: {}" + Requesturl);            Requesturl = HttpClientHelper.INSTANCE.get (Requesturl);                if (Requesturl! = null) {Matcher Matcher = Pattern.matcher (Requesturl);                    if (Matcher.find () && matcher.groupcount () = = 2) {double[] GPS = new double[2];                    Gps[0] = double.valueof (Matcher.group (1));                    GPS[1] = double.valueof (Matcher.group (2));                    System.out.println ("GPS: {}" + arrays.tostring (GPS));                return GPS;    }}} catch (Unsupportedencodingexception e) {} return null; } public static void Main (string[] args) {try {System.out.println (Testgaode.addresstogps ("Yanta District, Xi ' an, Shaanxi province        Xu Jia Zhuang cun));        } catch (IOException e) {e.printstacktrace (); }    }

}





The above code is found on the Internet, the use of httpclienthelper can be seen in the open source project sources: Http://git.oschina.net/277160299/helper

A web-based API that uses the high-D API to convert addresses to latitude and longitude

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.