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.OnDATEC lickListen er{
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.OnDATEC lickListen er whilst also implementing Google's OnlocationChangeListener. Whilst also having my code continue to extend fragment rather than fragmentactivity)
My Current Code:
Google Maps Location Change Listener Code:
implements DatePickerFragment.OnDATEC
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.OnDATEC
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;
}
}
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
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Although it wasn't a complete answer, it did help me to fix the problem
I'm glad that you got it solved!
ASKER
Do you know of any 'Genius/Expert' android developers who could help with that?