Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-03-12
4
Medium Priority
?
961 Views
Last Modified: 2014-03-12
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

0
Comment
Question by:KnightsTempla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 1500 total points
ID: 39925365
I don't really do much in the way of Android, but I do know Java and hopefully this question just boils down to a Java thing.

Firstly, there is no reason why you can "implement" ANY number of interfaces. Yes, you are right in that you can only "extend" one class, but implementing interfaces is different.

So, my though here is that you should be able to continue to extend the Fragment class, and have your code in the onCreateView method, and then just implement BOTH listener interfaces, ie.


public class HomeFragment extends Fragment implements DatePickerFragment.OnDATEClickListener, OnMyLocationChangeListener {

Then in your class you define method(s) that implement the OnDateClickListener interface (whatever they are, I could find any doc and your code doesn't show it) and then also have a method "onMyLocationChange" that implements the OnMyLocationChangeListener interface.
0
 

Author Comment

by:KnightsTempla
ID: 39925381
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?
0
 

Author Closing Comment

by:KnightsTempla
ID: 39925392
Although it wasn't a complete answer, it did help me to fix the problem
0
 
LVL 36

Expert Comment

by:mccarl
ID: 39925394
I'm glad that you got it solved!
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use the Google Now Launcher, as an aftermarket add on, have a Samsung Note 5 and are worried about power consumption be wary of using the ultra power saving mode.  Here is what happened to me when I made the mistake of trying this out...
There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question