2007-11-19
【Android】说做就做:都市列表+卫星地图
关键字: android,mapview
前言:为了得奖。。。android。。。T_T。。。
完成notepad 3部曲,又看了其他人的MapView使用例子,手痒啊,做了个简陋的都市列表,并用MapView来看卫星地图,还有目前路况(traffic,如果有的话),Zoom In/Out,纯抄袭,羞愧中。。。
基本上基于notepad样板,做了个City的list:(偷工减料,static一下了,其实应该从db或者web service上面拿。。。)
geocode是从IBM一个Perl的例子上copy的。。。
接下来把notepad copy一下,改成自己的东西。。。
现在是重点了,CityMap:
要extends MapActivity,因为是个View嘛。。。
在onCreate()里面拿到传递进去的city,然后拿city的geocode:
GeoPoint是个DTO/VO,里面就放两个float的经度和纬度:
搞定显示,接下来是key events:
i: zoom in
o: zoom out
s: satellite
t: traffic
最后加个回到城市list的menu:
完成notepad 3部曲,又看了其他人的MapView使用例子,手痒啊,做了个简陋的都市列表,并用MapView来看卫星地图,还有目前路况(traffic,如果有的话),Zoom In/Out,纯抄袭,羞愧中。。。
基本上基于notepad样板,做了个City的list:(偷工减料,static一下了,其实应该从db或者web service上面拿。。。)
java 代码
- static {
- cities = new ArrayList<String>();
- cities.add("beijing");
- cities.add("london");
- cities.add("bangalore");
- cities.add("potsdam");
- cities.add("brasilia");
- geocodes = new HashMap<String, GeoPoint>();
- geocodes.put("beijing", new GeoPoint(40.25f,116.5f));
- geocodes.put("london", new GeoPoint(51.52f,-0.1f));
- geocodes.put("bangalore", new GeoPoint(12.97f,77.56f));
- geocodes.put("potsdam", new GeoPoint(52.4f,13.07f));
- geocodes.put("brasilia", new GeoPoint(-15.78f,-47.91f));
- }
接下来把notepad copy一下,改成自己的东西。。。
java 代码
- @Override
- protected void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.city_list);
- fillData();
- }
- private void fillData() {
- ArrayAdapter<String> cities =
- new ArrayAdapter<String>(this, R.layout.city_row, MapConstants.cities);
- setListAdapter(cities);
- }
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- super.onListItemClick(l, v, position, id);
- Intent i = new Intent(this, CityMap.class);
- //这里传递选择的城市名字
- i.putExtra(MapConstants.CITY_NAME, MapConstants.cities.get(position));
- startSubActivity(i, ACTIVITY_VIEW);
- }
-
- //mapview 回来的时候显示城市list
- @Override
- protected void onActivityResult(int requestCode, int resultCode, String data, Bundle extras) {
- super.onActivityResult(requestCode, resultCode, data, extras);
- fillData();
- }
现在是重点了,CityMap:
java 代码
- public class CityMap extends MapActivity
要extends MapActivity,因为是个View嘛。。。
在onCreate()里面拿到传递进去的city,然后拿city的geocode:
java 代码
- private MapView myMapView;
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- Bundle extras = getIntent().getExtras();
- // get the geopoint by city
- String city = extras.getString(MapConstants.CITY_NAME);
- GeoPoint gp = MapConstants.geocodes.get(city);
GeoPoint是个DTO/VO,里面就放两个float的经度和纬度:
java 代码
- public class GeoPoint {
- private float latitude;
- private float longitude;
java 代码
- myMapView = new MapView(this);
-
- Point p = new Point((int) (gp.getLatitude() * 1000000),
- (int) (gp.getLongitude() * 1000000));
- // 地图控制器。。。
- MapController mc = myMapView.getController();
-
- mc.animateTo(p);
- // 21是最zoom in的一级,一共是1-21级
- mc.zoomTo(21);
- setContentView(myMapView);
- // 切换到卫星地图
- myMapView.toggleSatellite();
搞定显示,接下来是key events:
i: zoom in
o: zoom out
s: satellite
t: traffic
java 代码
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_I) {
- // zoom in
- myMapView.getController().zoomTo(myMapView.getZoomLevel() + 1);
- return true;
- } else if (keyCode == KeyEvent.KEYCODE_O) {
- // zoom out
- myMapView.getController().zoomTo(myMapView.getZoomLevel() - 1);
- return true;
- } else if (keyCode == KeyEvent.KEYCODE_S) {
- // 卫星地图
- myMapView.toggleSatellite();
- return true;
- } else if (keyCode == KeyEvent.KEYCODE_T) {
- // traffic,路况
- myMapView.toggleTraffic();
- return true;
- }
- return false;
- }
最后加个回到城市list的menu:
java 代码
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- super.onCreateOptionsMenu(menu);
- menu.add(0, EXIT_ID, R.string.exit_citymap);
- return true;
- }
- @Override
- public boolean onMenuItemSelected(int featureId, Item item) {
- super.onMenuItemSelected(featureId, item);
- switch(item.getId()) {
- case EXIT_ID:
- finish();
- break;
- }
- return true;
- }
评论
fastzch
2007-12-10
各位有在android中如何开发Web Service的教程或例子吗?
lordhong
2007-12-01
慢慢来,我也是刚起步,东抄西抄的...
qiuzhiqing
2007-11-30
跑了个HelloWorld!呵呵
差距啊~~~
差距啊~~~
andy54321
2007-11-26
暂时还没研究这个地步,看来差距不小呢
huanghero0663
2007-11-21
crazyox 写道
好东西, 不知道以后做这种手机软件的公司会不会多, 前景好不好啊!
关注中,希望又新的东西出来^_^
crazyox
2007-11-20
好东西, 不知道以后做这种手机软件的公司会不会多, 前景好不好啊!
lordhong
2007-11-20
今天就adb shell。。。rm了一把,NND,程序都改了,emulator竟然不把新的app load进去,真是白痴。。。害我debug半个多小时。。,
yb31
2007-11-19
试了下
adb shell 里已经有了.
重新rm掉.再install,或push也不行
adb shell 里已经有了.
重新rm掉.再install,或push也不行
fins
2007-11-19
lordhong 写道
我用adb install lordhong.MapDemo1.apk,然后显示0 bytes虾米的,emulator里面也找不到。。。怎么回事?严格按照google doc:
Running an Android Application
To run a compiled application, you will upload the .apk file to the /data/app/ directory in the emulator using the adb tool as described here:
1. Start the emulator (run <your_sdk_dir>/tools/emulator from the command line)
2. On the emulator, navigate to the home screen (it is best not to have that application running when you reinstall it on the emulator; press the Home key to navigate away from that application).
3. Run adb install myproject/bin/<appname>.apk to upload the executable. So, for example, to install the Lunar Lander sample, navigate in the command line to <your_sdk_dir>/sample/LunarLander and type ../../tools/adb install bin/LunarLander.apk
4. In the emulator, open the list of available applications, and scroll down to select and start your application.
—T.T...
Running an Android Application
To run a compiled application, you will upload the .apk file to the /data/app/ directory in the emulator using the adb tool as described here:
1. Start the emulator (run <your_sdk_dir>/tools/emulator from the command line)
2. On the emulator, navigate to the home screen (it is best not to have that application running when you reinstall it on the emulator; press the Home key to navigate away from that application).
3. Run adb install myproject/bin/<appname>.apk to upload the executable. So, for example, to install the Lunar Lander sample, navigate in the command line to <your_sdk_dir>/sample/LunarLander and type ../../tools/adb install bin/LunarLander.apk
4. In the emulator, open the list of available applications, and scroll down to select and start your application.
—T.T...
进 adb shell里 看不到?? 如果能看到 rm了 然后从新 push吧
fins
2007-11-19
lordhong 写道
我用adb install lordhong.MapDemo1.apk,然后显示0 bytes虾米的,emulator里面也找不到。。。怎么回事?严格按照google doc:
Running an Android Application
To run a compiled application, you will upload the .apk file to the /data/app/ directory in the emulator using the adb tool as described here:
1. Start the emulator (run <your_sdk_dir>/tools/emulator from the command line)
2. On the emulator, navigate to the home screen (it is best not to have that application running when you reinstall it on the emulator; press the Home key to navigate away from that application).
3. Run adb install myproject/bin/<appname>.apk to upload the executable. So, for example, to install the Lunar Lander sample, navigate in the command line to <your_sdk_dir>/sample/LunarLander and type ../../tools/adb install bin/LunarLander.apk
4. In the emulator, open the list of available applications, and scroll down to select and start your application.
—T.T...
Running an Android Application
To run a compiled application, you will upload the .apk file to the /data/app/ directory in the emulator using the adb tool as described here:
1. Start the emulator (run <your_sdk_dir>/tools/emulator from the command line)
2. On the emulator, navigate to the home screen (it is best not to have that application running when you reinstall it on the emulator; press the Home key to navigate away from that application).
3. Run adb install myproject/bin/<appname>.apk to upload the executable. So, for example, to install the Lunar Lander sample, navigate in the command line to <your_sdk_dir>/sample/LunarLander and type ../../tools/adb install bin/LunarLander.apk
4. In the emulator, open the list of available applications, and scroll down to select and start your application.
—T.T...
进 adb shell里 看不到?? 如果能看到 rm了 然后从新 push吧
crazyox
2007-11-19
今天javaeye是怎么了? 老打不开自己的博客?
crazyox
2007-11-19
android做出来的东西可以直接在手机上看?
lordhong
2007-11-19
我用adb install lordhong.MapDemo1.apk,然后显示0 bytes虾米的,emulator里面也找不到。。。怎么回事?严格按照google doc:
Running an Android Application
To run a compiled application, you will upload the .apk file to the /data/app/ directory in the emulator using the adb tool as described here:
1. Start the emulator (run <your_sdk_dir>/tools/emulator from the command line)
2. On the emulator, navigate to the home screen (it is best not to have that application running when you reinstall it on the emulator; press the Home key to navigate away from that application).
3. Run adb install myproject/bin/<appname>.apk to upload the executable. So, for example, to install the Lunar Lander sample, navigate in the command line to <your_sdk_dir>/sample/LunarLander and type ../../tools/adb install bin/LunarLander.apk
4. In the emulator, open the list of available applications, and scroll down to select and start your application.
—T.T...
Running an Android Application
To run a compiled application, you will upload the .apk file to the /data/app/ directory in the emulator using the adb tool as described here:
1. Start the emulator (run <your_sdk_dir>/tools/emulator from the command line)
2. On the emulator, navigate to the home screen (it is best not to have that application running when you reinstall it on the emulator; press the Home key to navigate away from that application).
3. Run adb install myproject/bin/<appname>.apk to upload the executable. So, for example, to install the Lunar Lander sample, navigate in the command line to <your_sdk_dir>/sample/LunarLander and type ../../tools/adb install bin/LunarLander.apk
4. In the emulator, open the list of available applications, and scroll down to select and start your application.
—T.T...
lordhong
2007-11-19
靠!有附件就发不上去,去掉附件就可以了,JE大bug啊。。。附件续上。。。
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 172286 次
- 性别:

- 来自: 在野

- 详细资料
搜索本博客
我的相册
IMG_0308
共 45 张
共 45 张
最近加入圈子
最新评论
-
Google I/O 大会keynote ...
看完这个视频,觉得跟iphone的效果也有一拼啊,而且android是开放式系统 ...
-- by yangzhihuan -
[转] 神秘诅咒
C&K社在je成立分社了?
-- by reed7 -
[转] 神秘诅咒
这年头,俯卧撑都不保险
-- by larryzou -
HTC Kaiser 编译Android ...
我在想能在pc上装个android么,电脑1开机就是1手机
-- by larryzou -
[转]透露社 - 爆雪将为 ...
三个俯卧撑后,会在听到“我去了”的咆哮声以后,召唤到无比强大的神秘跳水女战神
-- by larryzou






评论排行榜