- 浏览: 294354 次
- 性别:
- 来自: 上海
最新评论
-
再_见孙悟空:
写的不错
Dialog -
a549262189:
支持下,正好在学习这块的内容!
Android Gesture Detector -
dcsff:
受教了
LayoutInflater -
庆_啊:
真厉害。
LayoutInflater -
ghj234:
学习了,哈哈
LayoutInflater
<uses-library android:name="com.google.android.maps" /> </application> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-sdk android:minSdkVersion="3" /> </manifest>
mapview.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.google.android.maps.MapView android:id="@+id/mapview_mv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="0HYDh8uGZ3WWc58LxmauEVsNWqAGP_HSGFRzixQ" /> <LinearLayout android:id="@+id/mapview_llayout_zoom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> <RelativeLayout android:id="@+id/mapview_rlayout_search" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="@color/darkgray" android:visibility="invisible" android:paddingTop="8dip" android:paddingBottom="4dip" android:paddingLeft="8dip" android:paddingRight="8dip"> <AutoCompleteTextView android:id="@+id/mapview_autotxtview_search" android:layout_width="245dip" android:layout_height="wrap_content" android:text="@string/edt_search_default" android:textColor="@color/darkgray" android:layout_marginRight="6dip" /> <ImageButton android:id="@+id/mapview_imgbtn_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/ic_search_category_default" android:layout_toRightOf="@id/mapview_autotxtview_search" android:layout_alignBottom="@id/mapview_autotxtview_search" /> </RelativeLayout> </RelativeLayout>
public class ActivityMap extends MapActivity { private MapView mMapView; private GeoPoint gp; private LocationManager mLocMgr; public static Location mLoc; private String strLocInfo; private final LocationListener mLocListener = new LocationListener() { public void onLocationChanged(Location location) { refreshMapView(location); } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } }; protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.mapview); mMapView = (MapView) findViewById(R.id.mapview_mv); mLocMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); updateLocation(mLocMgr); refreshMapView(mLoc); // mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, mLocListener); mLocMgr.requestLocationUpdates(strLocInfo, 2000, 10, mLocListener); // zoom widget LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.mapview_llayout_zoom); View zoomView = mMapView.getZoomControls(); zoomLayout.addView(zoomView, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // mMapView.displayZoomControls(true); // mMapView.setBuiltInZoomControls(true); // mMapView.displayZoomControls(false); } private void refreshMapView(Location location) { updateGeoPoint(location); MapController mMapController = mMapView.getController(); mMapController.animateTo(gp); mMapController.setZoom(mMapView.getZoomLevel()); try { Log.e("************", getAddress(gp)); } catch (IOException e) { e.printStackTrace(); } } private void updateLocation(LocationManager lm) { Criteria mCriteria = new Criteria(); mCriteria.setAccuracy(Criteria.ACCURACY_FINE); // 经纬度是否精确提供 mCriteria.setAltitudeRequired(false); // 是否提供高度信息 mCriteria.setBearingRequired(false); // 是否提供航向信息 mCriteria.setCostAllowed(true); // 费用 mCriteria.setPowerRequirement(Criteria.POWER_LOW); strLocInfo = lm.getBestProvider(mCriteria, true); mLoc = lm.getLastKnownLocation(strLocInfo); if (mLoc == null) { mLoc = new Location(strLocInfo); mLoc.setLatitude(31.183333); mLoc.setLongitude(121.483333); } } private void updateGeoPoint(Location location) { double dLatitude = location.getLatitude() * 1E6; double dLongitude = location.getLongitude() * 1E6; gp = new GeoPoint( (int) (dLatitude), (int) (dLongitude) ); } private String getAddress(GeoPoint gp) throws IOException { double dLatitude = gp.getLatitudeE6() / 1E6; double dLongitude = gp.getLongitudeE6() / 1E6; //自经纬度取得地址 StringBuilder sb = new StringBuilder(); Geocoder gc = new Geocoder(ActivityMap.this, Locale.getDefault()); List<Address> lstAddr = gc.getFromLocation(dLatitude, dLongitude, 1); if (lstAddr.size() > 0) { Address addr = lstAddr.get(0); for (int i = 0; i < addr.getMaxAddressLineIndex(); i++) { sb.append(addr.getAddressLine(i)).append("\n"); } sb.append(addr.getLocality()).append("\n"); //所在地 sb.append(addr.getPostalCode()).append("\n"); //邮编 sb.append(addr.getCountryName()); } return sb.toString(); } public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.optionsmenu, menu); return super.onCreateOptionsMenu(menu); } public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.optionsmenu_search: Intent intent = new Intent(); intent.setClass(ActivityMap.this, ActivitySearch.class); startActivity(intent); break; case R.id.optionsmenu_directions: break; case R.id.optionsmenu_mapmode: break; case R.id.optionsmenu_mapmode_map: mMapView.setStreetView(true); mMapView.setSatellite(false); mMapView.setTraffic(false); break; case R.id.optionsmenu_mapmode_satellite: mMapView.setStreetView(false); mMapView.setSatellite(true); mMapView.setTraffic(false); break; case R.id.optionsmenu_mapmode_traffic: mMapView.setStreetView(false); mMapView.setSatellite(false); mMapView.setTraffic(true); break; case R.id.optionsmenu_myloc: MapOverlay mMapOverlay = new MapOverlay(); List<Overlay> listOfOverlay = mMapView.getOverlays(); listOfOverlay.clear(); listOfOverlay.add(mMapOverlay); mMapView.invalidate(); updateLocation(mLocMgr); refreshMapView(mLoc); break; } return super.onOptionsItemSelected(item); } protected boolean isRouteDisplayed() { return false; } private class MapOverlay extends com.google.android.maps.Overlay { public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); // translate the GeoPoint to screen pixels Point screenPts = new Point(); mapView.getProjection().toPixels(gp, screenPts); // add the marker Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_android); canvas.drawBitmap(bmp, screenPts.x, screenPts.y, null); return true; } } }
public class ActivitySearch extends MapActivity { private MapView mMapView; public static int screen_width, screen_height; protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.mapview); screen_width = getWindowManager().getDefaultDisplay().getWidth(); screen_height = getWindowManager().getDefaultDisplay().getHeight(); mMapView = (MapView) findViewById(R.id.mapview_mv); MapOverlay mMapOverlay = new MapOverlay(); List<Overlay> listOfOverlay = mMapView.getOverlays(); listOfOverlay.clear(); listOfOverlay.add(mMapOverlay); mMapView.invalidate(); RelativeLayout rLayout = (RelativeLayout) findViewById(R.id.mapview_rlayout_search); rLayout.setVisibility(View.VISIBLE); ImageButton btn_search = (ImageButton) findViewById(R.id.mapview_imgbtn_search); btn_search.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { } }); mMapView.setEnabled(false); } protected boolean isRouteDisplayed() { return false; } private class MapOverlay extends com.google.android.maps.Overlay { public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); Paint innerPaint = new Paint(); Paint borderPaint = new Paint(); innerPaint.setARGB(75, 80, 80, 80); // darkgray borderPaint.setARGB(255, 255, 255, 255); // white borderPaint.setAntiAlias(true); // 抗锯齿 borderPaint.setStyle(Style.STROKE); //描边,和Style.Fill相对 borderPaint.setStrokeWidth(2); RectF drawRect = new RectF(); drawRect.set(0,0, screen_width, screen_height); canvas.drawRoundRect(drawRect, 5, 5, innerPaint); canvas.drawRoundRect(drawRect, 5, 5, borderPaint); return true; } } }
22
发表评论
-
如果在Eclipse中debug
2010-05-02 14:15 0最基本的操作是: 1, 首先在一个java文件中设断点,然后 ... -
How to download sourcecode of android with cygwin
2010-04-14 16:07 5077cygwin是一个在windows平台 ... -
TelephoneManager
2010-03-08 16:04 01. protected void onCreate(Bun ... -
eclipse c
2010-03-07 21:05 0Eclipse 除 了可以开发Java之外,还支持了许 ... -
android sdk安装
2010-02-02 23:37 34471.下载:http://developer.android.c ... -
Toast
2010-02-02 23:35 14211. (1) public class ToastActi ... -
如何在MapView上画图
2010-02-02 23:34 1554http://ophone8.com/thread-4340- ... -
Service
2010-02-02 23:33 31091. Service生命周期 (1)Servic ... -
Notification
2010-02-02 23:33 18811. Notification构造器的参数 分别为: ... -
导航相关概念
2010-02-02 23:32 16711. Google Map的定位 (1)Goog ... -
PendingIntent和Intent
2010-02-02 23:28 9488Notification n = new Notificati ... -
Broadcast调用Service做的一个定时器
2010-02-02 23:28 36681. public class AlarmActivity ... -
Broadcast Receiver
2010-02-02 23:27 8654Broadcast Receiver用于接收并处理广播通知(b ... -
LayoutInflater
2010-02-02 23:27 21760一般来讲,我们用LayoutInflater做一件事:infl ... -
Android's Components 生命周期
2010-02-02 23:27 2105Android中,Component(activity、ser ... -
Activity文档翻译
2010-02-02 23:26 1539转自:http://www.blogjava.net/m ... -
Intent
2010-01-20 10:51 011 public class MumActivity ex ... -
aidl
2010-01-05 11:24 30221. android进程之间如何通讯呢(在不同的进程中怎样传递 ... -
Gallery 画廊
2009-12-17 20:25 33271. images.xml <?xml ver ... -
Intent中的Flag参数
2009-12-16 18:12 6439Intent i = new Intent(B.this, C ...
相关推荐
该Demo简单实现了,google map V2 地图的显示.
GOOGLE MAP api 7个案例。 CurrentAddress 得到当前位置 gMap 地形 路线 GoogleMapDemo 当前位置 MAP 绘制路线 MapView 放大缩小 WeatherMap 在MAP上添加图片 WorldCities 城市经纬度的切换 以及 动画切换效果
IOS应用源码之基于GoogleMap的Demo .zip
GoogleMap谷歌地图demo,调用GoogleMap api 实现的功能全面的地图工具
ios应用源码之有个朋友要googlemap的demo,做了个,需要的可以看看googlemapdemo
适用于谷歌地球离线瓦片下载,支持多线程应用下载,可下载1-19层谷歌地图
googlemap 地图 demo + doc
真实好用的javaweb上使用的googlemap的demo
google map v3 demo 数据库动态案例 php的
今天发了半天时间才把google map 这个demo搞定,中间走了不少弯路,特意记录下,备份。
google地图API实现的一个简单demo
IOS map 定位 Demo ,例子代码
Flex 4 加载Google Map地形图demo 源码
GISMap地图demo 两个版本,一个旧版本GISMap和GISMapNew,旧版本中需要在代码内部自己配置区域编号,搜索地址,类型等。 新版直接可以在界面的combox中直接选择区域,类型,制定关键词等。
一个Google地图入门的JSP+JS源代码,供初学者参考。。。。。。。。
map-demo,地图代码生成,可以提供地图自定义
IOS应用源码之有个朋友要GoogleMap的Demo,做了个,需要的可以看看GoogleMapDemo.zip
google_map_demo 使用 javascript 的 html 中的 Google Map api。 客观的 仅移动标记 演示链接
IOS应用源码——有个朋友要GoogleMap的Demo,做了个,需要的可以看看GoogleMapDemo.zip
baidu map API demo,显示运动轨迹,多点的轨迹