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 simply by invoking the corresponding API.
The detailed 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
with "|" The cut-off is the latitude-longitude coordinate. Assuming that interpolate is set to true, smooth alignment information is returned.
The value of key needs to be replaced with the key value that the user has requested.
Ordinary developers are able to run these queries 2,500 times per day. Java calls the code for the roads API such as the following:
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 result of the query is, for example, what you see:
Crawl road information using the Google Roads API (Java implementation)