Question

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.

Was it helpful?

Solution

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..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top