10 Replies - 1880 Views - Last Post: 01 October 2011 - 01:51 PM

#1 TheCompBoy   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 11:00 AM

Hello guys!
Im back and i learned something while i was gone.. And i hope this time i wont be called "Vampire"

Im trying to make the view change from traffic to satelite when a button in my options menu is pressed but its not working.. Here is my code: Here is my onCreate

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //Adding features for the map
    mainMap = (MapView)findViewById(R.id.mvMain);
    mainMap.setBuiltInZoomControls(true);

    //THESE I WILL USE!!!
    //mainMap.setSatellite(true);
    mainMap.setTraffic(true);
    mapViewControll = true;
    mapController = mainMap.getController();
}


here is my onOptionsItemSelected

public boolean onOptionsItemSelected(MenuItem item) {

    switch(item.getItemId()){

    //Change View
    case R.id.changeView:
        if(mapViewControll = false){
        mainMap.setSatellite(true);
        }

        else{
            mainMap.setTraffic(true);
        }
        break;

    //Help
    case R.id.help:
        break;

    }

    return super.onOptionsItemSelected(item);
}


I did set the mapViewControll boolean to true at the top of the code.. What can be a problem here??

i did try call the invalidate method but it didn't work..

This post has been edited by TheCompBoy: 01 October 2011 - 11:02 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Google Maps API change view when options menu button was pressed?

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12657
  • View blog
  • Posts: 45,831
  • Joined: 27-December 08

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 11:05 AM

You never setContentView() for the new View.
Was This Post Helpful? 0
  • +
  • -

#3 TheCompBoy   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 11:11 AM

View Postmacosxnerd101, on 01 October 2011 - 06:05 PM, said:

You never setContentView() for the new View.


Im not making two separate views i want the view that is active to change into Satelite View

the
setContentView(R.layout.main);

is setting content view i want when the options menu item is pressed to change
mainMap.setTraffic(true);
into
mainMap.setSatellite(true);

This post has been edited by TheCompBoy: 01 October 2011 - 11:12 AM

Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12657
  • View blog
  • Posts: 45,831
  • Joined: 27-December 08

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 12:42 PM

I saw this line if(mapViewControll = false){. The = operator is for assignments, and the == operator is for comparisons.
Was This Post Helpful? 0
  • +
  • -

#5 TheCompBoy   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 12:51 PM

View Postmacosxnerd101, on 01 October 2011 - 07:42 PM, said:

I saw this line if(mapViewControll = false){. The = operator is for assignments, and the == operator is for comparisons.


Oh ye i already saw that it was assigned to == at first but i changed it to = for testing..
Sorry :)
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12657
  • View blog
  • Posts: 45,831
  • Joined: 27-December 08

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 12:53 PM

Probably a dumb question- but did you add the Listener correctly? Are you sure that method is being called?
Was This Post Helpful? 0
  • +
  • -

#7 TheCompBoy   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 12:59 PM

View Postmacosxnerd101, on 01 October 2011 - 07:53 PM, said:

Probably a dumb question- but did you add the Listener correctly? Are you sure that method is being called?


Yes Sir!
I tried it :)
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12657
  • View blog
  • Posts: 45,831
  • Joined: 27-December 08

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 01:19 PM

You only want one or the other to be enabled at a time then? Try setting the other to false when you set one to true. The documentation will probably shed more light on each of those.
Was This Post Helpful? 1
  • +
  • -

#9 TheCompBoy   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 01:32 PM

View Postmacosxnerd101, on 01 October 2011 - 08:19 PM, said:

You only want one or the other to be enabled at a time then? Try setting the other to false when you set one to true. The documentation will probably shed more light on each of those.


Alright realy thanks for the help i will try it out.
Was This Post Helpful? 0
  • +
  • -

#10 TheCompBoy   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 01:49 PM

Problem solved.. As macosxnerd said here i didn't make the road view to false so i got some kind of view that was mixed with satellite and road view :)

Big thanks and a rep for you :)

EDIT: I can't give rep that feature was removed for me.

This post has been edited by TheCompBoy: 01 October 2011 - 01:55 PM

Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12657
  • View blog
  • Posts: 45,831
  • Joined: 27-December 08

Re: Google Maps API change view when options menu button was pressed?

Posted 01 October 2011 - 01:51 PM

Glad I could help! :)
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1