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