zoukankan      html  css  js  c++  java
  • Google MAP模板 java程序员

    //在不支持多点触屏的设备上实现地图的放大缩小
    
    //开启内置缩放控制,在地图下方显示2个缩放按钮
    
    Private MapView mapView=...
    
    mapView.setBulitInZoomControls(true);
    
    //设置地图等级
    
    mapView.setZoom(12);
    
     
    
    //通过编程方式控制
    
    获得MapController对象
    
    MapController mc=mapView.getController();
    
    放大缩小分别利用MapController的zoomIn()和zoomOut()方法
    
     
    
    改变地图视图
    mapView.setSatellite(true);//卫星模式
    
    mapView.setTraffic(true);//交通流量模式
    
    mapView.setStreetView(true);//街景模式
    
    修改地图属性
    
    mapView.setClickable(true);
    
    mapView.setEnabled(true);
    
    显示一个特定的位置
    
    String coordinates[] = {"39.90960456049752", "116.3972282409668"}; 
    double lat = Double.parseDouble(coordinates[0]); 
    double lng = Double.parseDouble(coordinates[1]); 
    p = new GeoPoint() 
    { 
        (int)(lat * 1E6); 
        (int)(lng * 1E6); 
    }; 
    mc.animateTo(p); 
    mapView.invalidate(); 
    增加标记:
    public class MainActivity extends MapActivity 
    { 
        private MapView mapView; 
        private MapConrtoller mc; 
        private GEOPoint p; 
        class MapOverlay extends Overlay 
        { 
            public boolean draw(Canvas canvas, MapView mapView, 
                                boolean shadow, long when) 
            { 
                super.draw(canvas, mapView, shadow); 
                Point screenPts = new Point(); 
                mapView.getProjection().toPixels(p, screenPts); 
                Bitmap bmp = BitmapFactory.decodeResource(getResource, R.drawable.pinicon); 
                canvas.drawBitmap(bmp, screenPts.x - 32, screenPts.y - 59, null); 
                return true; 
            } 
        } 
        public void onCreate(Bundle savedInstanceState) 
        { 
            ... 
            MapOverlay mapOverlay = new MapOverlay(); 
            list<Overlay> listOfOverlays = mapView.getOverlays(); 
            listOfOverlays.clear(); 
            listOfOverlays.add(mapOverlay); 
            mapView.invalidate();//note 
        } 
        protected boolean isRouteDisplayed() 
        { 
            return false; 
        } 
    } 
    //获取触摸位置
    //覆写overlay类的onTouchEvent()方法
    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    { 
        if(event.getAction() == 1) 
        { 
            GeoPoint p = mapView.getProjection().fromPixels((int)event.getX(), (int)event.getY()); 
        } 
        return false; 
    } 
    //给定经纬度,返回地址
    public String getAddresses()
    {
        String addressString="没有找到地址";
        Geocoder gc=new Geocoder(mMobileMap,Locale.getDefault());
        try
        {
            List<Address> addresses=gc.getFromLocation(mLocation.getLatitude(),mLocation.getLongitude(),1);
            StringBuilder sb=new StringBuilder();
            if(addresses.size()>0)
            {
                   Address address=addresses.get(0);
                    sb.append("地址: ");
                    for(int i=0;i<address.getMaxAddressLineIndex();i++)
                    {
                        sb.append(address.getAddressLine(i));
                    }
                    addressString=sb.toString();
            }
        }
        catch(IOException e)
        {
        }
        return addressString;
    }
    //给定名字,返回经纬度
    public void searchName(String name) 
    { 
        try 
        { 
            List<Address> addresses = mGeoCoder.getFromLocationName(name, 1); 
            if(addresses.size() > 0) 
            { 
                Address address = addresses.get(0); 
                mLocation.setLatitude(address.getLatitude()); 
                mLocation.setLongitude(address.getLongitude()); 
            } 
        } 
        catch(IOException e) 
        { 
        } 
    } 

  • 相关阅读:
    台州 OJ 3847 Mowing the Lawn 线性DP 单调队列
    洛谷 OJ P1417 烹调方案 01背包
    快速幂取模
    台州 OJ 2649 More is better 并查集
    UVa 1640
    UVa 11971
    UVa 10900
    UVa 11346
    UVa 10288
    UVa 1639
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215848.html
Copyright © 2011-2022 走看看