android mapview地图操作

 //根据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)

 

 

 

乱七八糟随便整理下,有时间在弄,有的是直接拿猪崽的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值