Get my location

2019-03-07 05:04发布

问题:

I have a ListFragment and I want to get the my location. In my Manifest I have added this:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

and my ListFragment´s code is here, but not works:

public class ListaLugaresFragment extends ListFragment implements LocationListener {


    GoogleMap googleMap;
    Location location;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
         v= inflater.inflate(R.layout.lista, container, false);

         LocationManager lm = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE);
         lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);


         return v;

    }

    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub

        Toast.makeText(getActivity(), location.getLatitude()+""+location.getLongitude(), Toast.LENGTH_LONG).show();


    }

回答1:

First you need to know about GPS, Network Provider, google MAP to know getting location. Below example is for beginner to know how to get location(lanlat value) from the GPS and Network Provider

Follow this link:

Getting location (latlong)

If you want to get a location name then u must know about SHA code and all.

Follow this Link:

Getting location from googlemap