用于Android的离线谷歌地图与gps

时间:2013-01-27 15:46:21

标签: android google-maps gps

当我连接到互联网时,我已经制作了一张完整的地图,但是我想使用地图,即使没有互联网连接,也必须向我显示我最适合在线地图的地理位置。现在我的问题是,我是否必须再次使用新实现制作离线地图的新项目,或者我可以离线使用我自己的地图并对其进行一些更改。请指导我接下来要做的事情。

       map=(MapView) findViewById(R.id.mvmain);
    map.setBuiltInZoomControls(true);
    touchy t=new touchy();
    overlayList=map.getOverlays();
    overlayList.add(t);
    compass= new MyLocationOverlay(Main.this, map);
    overlayList.add(compass);
    controller= map.getController();

    mapSearchBox = (EditText) findViewById(R.id.map);

    mapSearchBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
             if (actionId == EditorInfo.IME_ACTION_SEARCH ||
                    actionId == EditorInfo.IME_ACTION_DONE ||
                    actionId == EditorInfo.IME_ACTION_GO ||
                    event.getAction() == KeyEvent.ACTION_DOWN &&
                    event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {

                // hide virtual keyboard
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mapSearchBox.getWindowToken(), 0);

                new SearchClicked(mapSearchBox.getText().toString()).execute();
                mapSearchBox.setText("", TextView.BufferType.EDITABLE);
                return true;
            }
            return false;
        }
    });



    d =getResources().getDrawable(R.drawable.aa);       
    controller.setZoom(6);

    //Placing pinpoint at location
    lm=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria crit=new Criteria();
    towers=lm.getBestProvider(crit, false);
    Location location=lm.getLastKnownLocation(towers);
    if(location !=null)
    {
        lat=(int) (location.getLatitude() *1E6);
        longi=(int) (location.getLongitude() *1E6);         
        GeoPoint ourLocation= new GeoPoint(lat,longi);
        OverlayItem overlayItem= new OverlayItem(ourLocation,"","");
        CustomPinpoint custom=new CustomPinpoint(d,Main.this);
        custom.insertPinPoint(overlayItem);
        overlayList.add(custom);



    }
    else
    {
        Toast.makeText(Main.this,"Couldn't get provider",                     Toast.LENGTH_SHORT).show();

    }

        }

1 个答案:

答案 0 :(得分:2)

如果没有互联网,您无法显示谷歌地图。您可以尝试显示离线标题的OSMDroid