Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-03-12
4
Medium Priority
?
976 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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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...
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Suggested Courses

916 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