//根据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)
乱七八糟随便整理下,有时间在弄,有的是直接拿猪崽的