1

I am facing a problem of adding overlays. I want to add button which will toggle between normal and satelitte view, and some textView, which will display my actual coordinates and those will be updated on my location change. I tried to put there classic TextView, added into my map.java import for using GPS, and onLocationChanged I am trying to update TextView's, but no success. It must be done via Overlays, but I can't see, how to set on the screen my desired items - button with specific function and regularly updated textView. Any ideas?

THanks

edit:

        int g=0;
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setEnabled(true);
        mapView.setClickable(true);

       @Override
       public void onClick(View v) {
        switch (v.getId()) {
        case R.id.toggle:
            if (g!=1){
                mapView.invalidate();
                mapView.setSatellite(true);
                mapView.invalidate();
                g=1;
            }else{
                mapView.invalidate();
                mapView.setSatellite(false);
                mapView.invalidate();
            }
            break;

           }
       }
Waypoint
  • 17,283
  • 39
  • 116
  • 170

2 Answers2

3

You don't need a overlay for this. Just define you layout using a layout xml file with an RelativeLayout as root element.

With a relative layout you can place elements like TextViews or a Buttons on top of each other. So in your case you would first define the MapView in your layout file and then the elements you want to display on the MapView. Now all elements should be rendered in the upper left corner on top of each other. Using the attributes defined by the RelativeLayout you can now align your elements in the way you want. Have a look at the RealtiveLayout tutorial for a better understanding.

Flo
  • 27,355
  • 15
  • 87
  • 125
  • Nope, I have tried button for toggling satelite view and it is simply not working. On click - I set up mapView.setSatellite(true) and nothing is happening – Waypoint Apr 06 '11 at 08:46
  • my question is edited, it simple, I have mapView, then in layout I have button with id toggle. I have implemented onClickListener and bounded it with button. – Waypoint Apr 06 '11 at 09:23
  • Have you debugged you code? Is the onClickListener called? Is mapView.setSatellite(true) called? – Flo Apr 06 '11 at 09:36
  • No problem, you're welcome. Sometimes just talking about a problem or explaining it to others helps finding a mistake/solution. ;) – Flo Apr 06 '11 at 10:30
  • what if i want to add my own "my_location" button on the map in map v2 for android. (I need this because i want to call some functionality which i can not call when google's my_location button will be clicked - Correct me if i m wrong...) – Bhavana Vadodariya Mar 08 '13 at 13:16