google maps - GPS Co-ordinates donot change upon moving - Android -



google maps - GPS Co-ordinates donot change upon moving - Android -

i have implemented simple app on device gets , displays gps latitude , longitude. co-ordinates donot alter when move in building. here implementation:

foodactivity.java

public class foodactivity extends activity { locationlistener mloclistener; location location; string provider; private double latitude = 0; private double longitude = 0; private handler mhandler; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_custom_title); setcontentview(r.layout.activity_food); getwindow().setfeatureint(window.feature_custom_title, r.layout.header_food); locationmanager mlocmanager = (locationmanager) getsystemservice(context.location_service); criteria criteria = new criteria(); provider = mlocmanager.getbestprovider(criteria, false); if (provider != null && !provider.equals("")) { location = mlocmanager.getlastknownlocation(provider); mloclistener = new mylocationlistener(); mlocmanager.requestlocationupdates(provider, 0, 0, mloclistener); if (location != null) { mhandler = new handler(); mhandler.postdelayed(updatetask, 0); } else { toast.maketext(getbasecontext(), "location can;t retrieved", toast.length_short).show(); } } else { toast.maketext(getbasecontext(), "no provider found", toast.length_short).show(); } } /* class location listener */ public class mylocationlistener implements locationlistener { @override public void onlocationchanged(location loc) { // todo auto-generated method stub textview lats = (textview) findviewbyid(r.id.tv_latitude); textview longs = (textview) findviewbyid(r.id.tv_longitude); latitude = loc.getlatitude(); longitude = loc.getlongitude(); lats.settext("latitude :" + latitude); longs.settext("longitude :" + longitude); } @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub } @override public void onproviderenabled(string provider) { // todo auto-generated method stub toast.maketext(getapplicationcontext(), "gps enabled", toast.length_short).show(); } @override public void onproviderdisabled(string provider) { // todo auto-generated method stub toast.maketext(getapplicationcontext(), "gps disabled", toast.length_short).show(); } } public runnable updatetask = new runnable(){ public void run(){ mloclistener.onlocationchanged(location); mhandler.postdelayed(updatetask,50000); } }; }

activity_food.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context="com.example.hkuapp.foodactivity"> <textview android:text="hello" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv_latitude" android:layout_below="@+id/tv_longitude" android:layout_alignparentleft="true" android:layout_margintop="32dp" /> <textview android:text="yo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv_longitude"/> </relativelayout>

in method mlocmanager.requestlocationupdates(provider, 0, 0, mloclistener); sec parameter time interval between location updates, in milliseconds. seek alter 1000 (1 second).

android google-maps gps

Comments