android mapview地图操作
2010-07-15 23:01
375 查看
//根据GeoPooint获得地址名称等详情
public String getAddressbyGeoPoint(GeoPoint gp)
{
String strReturn = "";
try
{
if (gp != null)
{
Geocoder gc = new Geocoder(SearchMap.this, Locale.getDefault());
double geoLatitude = (int)gp.getLatitudeE6()/1E6;
double geoLongitude = (int)gp.getLongitudeE6()/1E6;
List<Address> lstAddress = gc.getFromLocation(geoLatitude, geoLongitude, 1);
StringBuilder sb = new StringBuilder();
if (lstAddress.size() > 0)
{
Address adsLocation = lstAddress.get(0);
for (int i = 0; i < adsLocation.getMaxAddressLineIndex(); i++)
{
sb.append(adsLocation.getAddressLine(i)).append("/n");
}
sb.append(adsLocation.getLocality()).append("/n");
sb.append(adsLocation.getPostalCode()).append("/n");
sb.append(adsLocation.getCountryName());
}
strReturn = sb.toString();
}
}
catch(Exception e)
{
e.printStackTrace();
}
return strReturn;
}
//根据location获得GeoPoint
private GeoPoint getGeoByLocation(Location location)
{
GeoPoint gp = null;
try
{
if (location != null)
{
double geoLatitude = location.getLatitude()*1E6;
double geoLongitude = location.getLongitude()*1E6;
gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return gp;
}
放大缩小
mMapController01.setZoom(intZoomLevel);
//获得location信息
public Location getLocationPrivider(LocationManager lm)
{
Location retLocation = null;
try
{
Criteria mCriteria01 = new Criteria();
mCriteria01.setAccuracy(Criteria.ACCURACY_FINE);
mCriteria01.setAltitudeRequired(false);
mCriteria01.setBearingRequired(false);
mCriteria01.setCostAllowed(true);
mCriteria01.setPowerRequirement(Criteria.POWER_LOW);
strLocationPrivider = lm.getBestProvider(mCriteria01, true);
retLocation = lm.getLastKnownLocation(strLocationPrivider);
}
catch(Exception e)
{
e.printStackTrace();
}
return retLocation;
}
GPS当前位置更改
mLocationManager01.requestLocationUpdates(strLocationPrivider, 2000, 10, mLocationListener01);
public final LocationListener mLocationListener01 = new LocationListener()
{
//当前坐标改变时发生
public void onLocationChanged(Location location)
{
// TODO Auto-generated method stub
}
public void onProviderDisabled(String provider)
{
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider)
{
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
// TODO Auto-generated method stub
}
};
地图标记
Projection projection = mapView.getProjection();
Point p = new Point();
projection.toPixels(mGeoPoint, p);
Bitmap bmp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.niao);
Paint paint = new Paint();
canvas.drawBitmap(bmp, p.x, p.y, paint);
//地图标记加触发事件
使用ItemizedOverlay
事件为protected boolean onTap(int pIndex)
乱七八糟随便整理下,有时间在弄,有的是直接拿猪崽的
public String getAddressbyGeoPoint(GeoPoint gp)
{
String strReturn = "";
try
{
if (gp != null)
{
Geocoder gc = new Geocoder(SearchMap.this, Locale.getDefault());
double geoLatitude = (int)gp.getLatitudeE6()/1E6;
double geoLongitude = (int)gp.getLongitudeE6()/1E6;
List<Address> lstAddress = gc.getFromLocation(geoLatitude, geoLongitude, 1);
StringBuilder sb = new StringBuilder();
if (lstAddress.size() > 0)
{
Address adsLocation = lstAddress.get(0);
for (int i = 0; i < adsLocation.getMaxAddressLineIndex(); i++)
{
sb.append(adsLocation.getAddressLine(i)).append("/n");
}
sb.append(adsLocation.getLocality()).append("/n");
sb.append(adsLocation.getPostalCode()).append("/n");
sb.append(adsLocation.getCountryName());
}
strReturn = sb.toString();
}
}
catch(Exception e)
{
e.printStackTrace();
}
return strReturn;
}
//根据location获得GeoPoint
private GeoPoint getGeoByLocation(Location location)
{
GeoPoint gp = null;
try
{
if (location != null)
{
double geoLatitude = location.getLatitude()*1E6;
double geoLongitude = location.getLongitude()*1E6;
gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return gp;
}
放大缩小
mMapController01.setZoom(intZoomLevel);
//获得location信息
public Location getLocationPrivider(LocationManager lm)
{
Location retLocation = null;
try
{
Criteria mCriteria01 = new Criteria();
mCriteria01.setAccuracy(Criteria.ACCURACY_FINE);
mCriteria01.setAltitudeRequired(false);
mCriteria01.setBearingRequired(false);
mCriteria01.setCostAllowed(true);
mCriteria01.setPowerRequirement(Criteria.POWER_LOW);
strLocationPrivider = lm.getBestProvider(mCriteria01, true);
retLocation = lm.getLastKnownLocation(strLocationPrivider);
}
catch(Exception e)
{
e.printStackTrace();
}
return retLocation;
}
GPS当前位置更改
mLocationManager01.requestLocationUpdates(strLocationPrivider, 2000, 10, mLocationListener01);
public final LocationListener mLocationListener01 = new LocationListener()
{
//当前坐标改变时发生
public void onLocationChanged(Location location)
{
// TODO Auto-generated method stub
}
public void onProviderDisabled(String provider)
{
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider)
{
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
// TODO Auto-generated method stub
}
};
地图标记
Projection projection = mapView.getProjection();
Point p = new Point();
projection.toPixels(mGeoPoint, p);
Bitmap bmp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.niao);
Paint paint = new Paint();
canvas.drawBitmap(bmp, p.x, p.y, paint);
//地图标记加触发事件
使用ItemizedOverlay
事件为protected boolean onTap(int pIndex)
乱七八糟随便整理下,有时间在弄,有的是直接拿猪崽的
相关文章推荐
- ArcGIS for Android 地图控件 mapview 的常见操作
- Android 百度地图开发-setOnTouchListener方法给mapView设置了OnTouchListener后地图无法拖动的问题
- 2D高德Android地图SDK 新手入门的com.amap.api.maps.MapView的坑
- Android 使用百度地图SDK 定位和显示基础地图常见错误 locationclient.start()和mapview is null等等
- Android Google Map实例 - 在地图和卫星图之间切换(Android mapview)
- Android地图MapView中apiKey的申请过程
- 安卓智能地图开发与实施四:二维地图的MapView与Layers - ArcGIS Runtime SDK for Android(Version 100.0.0)
- Android地图MapView中apiKey的申请过程
- Android MapView 实现双击自动扩大地图
- android自定义view之地图(一)
- [无限互联]地图框架MapView(采用MKMapView)
- android:ScrollView内嵌套ListView、MapView等滑动冲突
- Android地图开发之BingMap基础教程
- 关于Android.widget.Button cannot be cast to com.esri.android.map.MapView错误的问题
- Android应用程序开发之图片操作(一)——Bitmap,surfaceview,imageview,Canvas
- 使用地图控件MapView如何申请apiKe…
- Android WebView的几个操作
- 【Android 应用开发】 自定义组件 宽高适配方法, 手势监听器操作组件, 回调接口维护策略, 绘制方法分析 -- 基于 WheelView 组件分析自定义组件
- 【Android 非人为操作的UI更新】在onCreate()和onResume()等方法中的更新UI操作方法及获取View的相关消息
- Arcgis for android Error inflating class com.esri.android.map.MapView