Get my location

五迷三道 提交于 2019-12-02 23:40:54

问题


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



来源:https://stackoverflow.com/questions/24118377/get-my-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!