The Google Roads API provides a powerful road acquisition interface that allows users to access the corresponding area's road coordinates and the speed limit information of the corridor by simply invoking the appropriate API. The specific invocation method is as follows:
HTTPS://roads.googleapis.com/v1/snaptoroads?path=-35.27801,149.12958|-35.28032,149.12907|-35.28099,149.12929|- 35.28144,149.12984|-35.28194,149.13003|-35.28282,149.12956|-35.28302,149.12881|-35.28473,149.12836
&interpolate=true
&Key=API_KEY
where the "|" The split is latitude-longitude coordinates, and if Interpolate is set to true, smooth alignment information is returned. The value of key needs to be replaced with the key value of the user's own application. The average developer can perform these queries 2,500 times a day. Java calls the code for the Roads API as follows:
StringBuffer document = new StringBuffer (); try {String Str_url = "https://roads.googleapis.com/v1/snapToRoads?path=-35.27801,149.12958|-35.28032,149.1290 7|-35.28099,149.12929|-35.28144,149.12984|-35.28194,149.13003|-35.28282,149.12956|-35.28302,149.12881|- 35.28473,149.12836&interpolate=true&key=yourkeyhere "; URL url = new URL (str_url);//remote URL URLConnection conn = url.openconnection (); BufferedReader reader = new BufferedReader (New InputStreamReader (Conn.getinputstream ())); String line = null; int line_number = 0; while (line = Reader.readline ()) = null) {Line_number + = 1; if (Line.startswith ("\" latitude\ ":")) {line = Line.replaceall ("\" latitude\ ":", ""); Document.append (line + ""); System.out.print (line); } if (Line.startswith ("\" longitude\ ":")) { line = Line.replaceall ("\" longitude\ ":", ""); Document.append (line + ""); System.out.println (line); }} if (Line_number <) {System.out.println ("error"); } reader.close (); } catch (Malformedurlexception e) {e.printstacktrace (); } catch (IOException e) {e.printstacktrace (); }
The results of the query are as follows:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Crawl road information using the Google Roads API (Java implementation)