Link to home
Start Free TrialLog in
Avatar of KnightsTempla
KnightsTempla

asked on

Want to use GoogleMaps - OnMyLocationChangeListener but can't implement it? Any other options

I want to utilize Google Maps, OnlocationChangeListener but because I've already implemented

implements DatePickerFragment.OnDATEClickListener{

And as the above needs to remain implemented, this is making implementing OnlocationChangeListener very difficult. Also the  onLocationchangelistener code currently extends fragmentActivity whereas my current codeextends  fragment which creates further problems.

The problem is: I can't extend or implement anything else as I'm already implementing and extending. Which means I can't get OnlocationChangeListener to work

Do you know of any work around?

(To allow me to implement DatePickerFragment.OnDATEClickListener whilst also implementing Google's OnlocationChangeListener. Whilst also having my code continue to extend fragment rather than fragmentactivity)

My Current Code:
    public class HomeFragment extends Fragment implements DatePickerFragment.OnDATEClickListener{
         
        public HomeFragment(){}
         
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
      
            View rootView = inflater.inflate(R.layout.fragment_home, container, false);
              
            return rootView;
        }
    }

Open in new window


Google Maps Location Change Listener Code:
        public class MainActivity extends FragmentActivity implements OnMyLocationChangeListener {
        	
        	GoogleMap googleMap;
        	
        	@Override
        	protected void onCreate(Bundle savedInstanceState) {
        		super.onCreate(savedInstanceState);
        		setContentView(R.layout.activity_main);
        		
        		// Getting Google Play availability status
                int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
        
                // Showing status
                if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available        	
                	int requestCode = 10;
                    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
                    dialog.show();
                    
                }else {	// Google Play Services are available	
        		
        			// Getting reference to the SupportMapFragment of activity_main.xml
        			SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        			
        			// Getting GoogleMap object from the fragment
        			googleMap = fm.getMap();
        			
        			// Enabling MyLocation Layer of Google Map
        			googleMap.setMyLocationEnabled(true);			
        			
        			// Setting event handler for location change
        			googleMap.setOnMyLocationChangeListener(this);		
        			
                }
        		
        	}
        	
        
        	@Override
        	public boolean onCreateOptionsMenu(Menu menu) {
        		// Inflate the menu; this adds items to the action bar if it is present.
        		getMenuInflater().inflate(R.menu.activity_main, menu);
        		return true;
        	}
        
        
        	@Override
        	public void onMyLocationChange(Location location) {
    
    //Location stuff
        		
        	}
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KnightsTempla
KnightsTempla

ASKER

You were correct in that I can implement more than one interface but I still need help in reference to modifying the above code so it can run on fragment rather than fragment-activity?

Do you know of any 'Genius/Expert' android developers who could help with that?
Although it wasn't a complete answer, it did help me to fix the problem
I'm glad that you got it solved!