Crawl road information using the Google Roads API (Java implementation)

Source: Internet
Author: User

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)

Related Article

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.