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 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)

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.