• 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) 
        { 
        } 
    } 

  • 相关阅读:
    mysql字符生命周期
    mysql5.6特殊字符问题
    电信网关-天翼网关-GPON-HS8145C设置桥接路由拨号认证
    linux-shell脚本高并发对文本url批量下载
    Kettle7.1在window启动报错
    微软的在线文档存储OneDrive使用帮助
    centos6.5搭建redmine3.4
    mysql基础拓扑图
    线上应用故障排查之一:高CPU占用
    线上服务CPU100%问题快速定位实战
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215848.html
Copyright © 2020-2023  润新知