(In Android 0.9 and previous SDKs, there has always been a package of com. Google. Google nav, which can be used to implement many complex functions related to Google Maps, such as the explicit two point approach I will talk about today. However, since the 1.0 SDK, this package has been removed, which makes it impossible for many early Android programs to compile and run, and the related functions cannot be realized. Google promised to open Android early on, and it is understandable to remove some high-end APIs on the eve of open source. In addition, it provides a great Intent mechanism for us to call the built-in Google Maps. I saw a related article on the blog of Jeffrey Sharkey, the author of CompareEverywhere, and learned a method. First of all, we need to know that you can enter similar maps. Google/maps in a PC browser? A URL such as f=dsaddr=shanghaidaddr=hangzhouhl=en can get a route from Shanghai to Hangzhou in the browser. Among them, saddr indicates the starting position, and daddr indicates the destination location. Of course, longitude and latitude of X and Y can also be used. After knowing this, we can use Intent to create an activity to help us. Android will automatically find and start a suitable application. If there are multiple applications that can open this URL, it will let users choose. I wrote a very simple Sample. The first few sentences are as follows: 1Stringuri=maps. Google/maps? f=dsaddr= strFrom ,daddr= strTo hl=en; Log.i(RouteSample,uri= uri); startActivity(newIntent(Intent.ACTION_VIEW,Uri.parse(uri))); After the user has entered the starting point and destination, and admitted that in the future, Android pop-up dialog box allows the user to select the appropriate application. After we choose Maps, the way from Shanghai to Hangzhou will be explicitly shown on the map. In this example, we use the Android Intent to start a new activity and explicitly show the path between the two points we need. Because we use the functions of Google Maps, there are not many tools that can be customized. Of course, I think the most important point of this example is to show the smart usage of Android Intent (this usage is not mentioned in the official IntentsList). This document includes the following annexes:
RouteSample\bin\com\demo\routesample\R$attr.class
RouteSample\bin\com\demo\routesample\R$drawable.class
RouteSample\bin\com\demo\routesample\R$id.class
RouteSample\bin\com\demo\routesample\R$layout.class
RouteSample\bin\com\demo\routesample\R$string.class
RouteSample\bin\com\demo\routesample\R.class
RouteSample\bin\com\demo\routesample\RouteSample$1.class
RouteSample\bin\com\demo\routesample\RouteSample.class
RouteSample\bin\classes.dex
RouteSample\bin\resources.ap_
RouteSample\bin\RouteSample.apk
RouteSample\res\drawable\icon.png
RouteSample\res\layout\main.xml
RouteSample\res\values\strings.xml
RouteSample\src\com\demo\routesample\R.java
RouteSample\src\com\demo\routesample\RouteSample.java
RouteSample\.classpath
RouteSample\.project
RouteSample\AndroidManifest.xml)