w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Google location service updates ignoring location listener (android)

Typically right before I call and use GoogleMap I instantiate the supportfragmentmanager then use this to instantiate the map. Like below I hope this helps.

    lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
    SupportMapFragment mf= (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);


    map = mf.getMap();

    //map = ((MapFragment)
getFragmentManager().findFragmentById(R.id.map)).getMap();
    ll = new SecondPointLocationListener();

As far as your method for printing the location use this instead...

@Override
public void onConnected(Bundle arg0) 
{
    Toast.makeText(context, "GPS connected", Toast.LENGTH_SHORT).show();
    connector = new Connector();
    connector.execute("clues", null, null);
    listener = new LocationListener()
    {
        @Override
        public void onLocationChanged(Location location) 
        {
            Log.d("location", "listener activated");
            try
            {
            double[] coords = locationCoords(location);
            if(coords[0] != 0)
            {
                map.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(coords[0], coords[1]), (float) 14.5));

            }

            Double latitude = location.getLatitude();
            Double longitude = location.getLongitude();
            Toast.makeText(context,"Latitude = "+ latitude + "" +"Longitude
 "+ longitude,
                    Toast.LENGTH_LONG).show();
            }
            catch(NullPointerException e)
            {
                Log.d("nulls", "null");
            }

        }
    };
    mLocationClient.requestLocationUpdates(mLocationRequest, listener);
    Log.d("location", "location updates initiated");




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.