找回密码
 立即注册
android开发 2022-10-28 47 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
在Android0.9以及之前的SDK中,一向有一个com.谷歌.谷歌nav的package,可以用来实现很多和Google地图相关的复杂功能,比如我今日要讲的显式两点间途径等。可是从1.0的SDK开始这个package被移除了,这使得很多前期的Android程序无法编译和运行,相关的功能也就无法实现了——Google一早就许诺会把Android开源,在开源的前夕移除一些比较高档的API也是可以理解的,况且他提供了很棒的Intent机制让我们调用内置的GoogleMaps。我在CompareEverywhere的作者JeffreySharkey的blog上看到了相关的一篇文章,学到了一个方法。首先我们需求认识一点,即在PC浏览器中输入相似maps.谷歌/maps?f=dsaddr=shanghaidaddr=hangzhouhl=en这样的URL就可以在浏览器中得到一个从上海到杭州的途径,其中,saddr表明起点方位,daddr则表明目的地方位,当然也可以使用如X,Y的经纬度来表明。认识了这一点今后,我们就可以使用Intent新建一个Activity来帮助我们。Android会自动找到并启动适合的使用程序,如果有多个可以打开这个URL的使用程序,它就会让用户选择。我写了一个很简单的Sample,首要的几句代码如下:1Stringuri=maps.谷歌/maps?f=dsaddr=+strFrom+,daddr=+strTo+hl=en;Log.i(RouteSample,uri=+uri);startActivity(newIntent(Intent.ACTION_VIEW,Uri.parse(uri)));在用户输入完起点和目的地,并承认今后,Android弹出对话框让用户选择适合的使用程序。我们选择Maps今后,上海到杭州的途径就显式在地图上了。在这个比如中,我们使用了Android的Intent来启动了一个新的Activity,并显式了我们所需求的两点间的途径。因为我们是使用了GoogleMaps的功能,所以功能上没有多少工具可以定制。当然我觉得这个比如最首要的一点是展现了Android的Intent的灵敏用法(官方的IntentsList中被没有提及这个用法)。本资料共包括以下附件:
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

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

[下载]12242218993.rar




上一篇:Android 录音程序源码
下一篇:Rss 订阅源码Dem