简体   繁体   中英

Android MapView (google maps) v1 focus by Locale or country name

when you go to Google maps in the browser you can type a country name and the map focuses on that country. Is it possible to get this on a MapView? I'd like my MapView to initially focus on user's country if a location is not available.

EDIT: here's what I have so far:

private MapView mvClear;
private MyLocationOverlay compass;
private MapController controller;

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_clear_map);

   mvClear = (MapView) findViewById(R.id.mvClear);
   mvClear.setBuiltInZoomControls(true);

   TouchOverlay touchOverlay = new TouchOverlay();
   List<Overlay> overlays = mvClear.getOverlays();
   overlays.add(touchOverlay);

   compass = new MyLocationOverlay(this, mvClear);
   overlays.add(compass);

   controller = mvClear.getController();
   controller.setZoom(8);

   Geocoder coder = new Geocoder(this);
   try {
       List<Address> address = coder.getFromLocationName(Locale.getDefault().getCountry(), 1);
       int lat = (int) address.get(0).getLatitude();
       int lon = (int) address.get(0).getLongitude();
       GeoPoint point = new GeoPoint(lat, lon);
       controller.setCenter(point);
   } catch (IOException e) {
       e.printStackTrace();
   }
}

No focus.

Best solution I found was to save the default center point as String resource so it can be "translated" if the app is localized. That's it for now..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM