Guest User

Untitled

a guest
Nov 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.17 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="#ffffff">
  6.  
  7. <Button
  8. android:id="@+id/BackButton"
  9.  
  10. android:text="Back"
  11. android:textColor="#FFFF"
  12. android:textSize="30sp"
  13.  
  14. android:layout_width="240dp"
  15. android:layout_height="40dp"
  16. android:background="@drawable/shapecurvedrectangledarkblue"
  17. android:layout_alignParentBottom="true"
  18. android:layout_centerHorizontal="true"
  19. android:layout_marginBottom="10dp" />
  20.  
  21. <TextView
  22. android:text="Your Current Location"
  23. android:textAlignment="center"
  24. android:layout_height="30dp"
  25. android:textSize="25sp"
  26. android:textColor="#FFFFFF"
  27. android:background="#4267b2"
  28. android:id="@+id/TextView1"
  29. android:layout_width="match_parent"
  30. android:layout_marginTop="5dp"
  31. android:layout_alignParentTop="true"
  32. android:layout_alignParentLeft="true"
  33. android:layout_alignParentStart="true" />
  34.  
  35. <TextView
  36. android:text="Near by bus stand/stop"
  37. android:layout_width="match_parent"
  38. android:textAlignment="center"
  39. android:textColor="#FFFFFF"
  40. android:textSize="25sp"
  41.  
  42. android:background="#4267b2"
  43. android:layout_height="30dp"
  44. android:layout_below="@+id/TextView1"
  45. android:layout_alignParentLeft="true"
  46. android:layout_alignParentStart="true"
  47. android:layout_marginTop="40dp"
  48. android:id="@+id/textView" />
  49.  
  50. <TextView
  51. android:id="@+id/textView3"
  52. android:textAlignment="center"
  53. android:textColor="#4267b2"
  54. android:textSize="25sp"
  55. android:layout_width="wrap_content"
  56. android:layout_height="wrap_content"
  57. android:text="CurrentLocation"
  58. android:layout_alignParentLeft="true"
  59. android:layout_alignParentStart="true"
  60. android:layout_alignParentRight="true"
  61. android:layout_alignParentEnd="true"
  62. android:layout_below="@+id/TextView1" />
  63.  
  64. <TextView
  65. android:id="@+id/textView4"
  66. android:textAlignment="center"
  67. android:textColor="#4267b2"
  68. android:textSize="25sp"
  69. android:layout_width="wrap_content"
  70. android:layout_height="wrap_content"
  71. android:layout_below="@+id/textView"
  72. android:text="NearBy1"
  73. android:layout_alignParentLeft="true"
  74. android:layout_alignParentStart="true"
  75. android:layout_alignParentRight="true"
  76. android:layout_alignParentEnd="true" />
  77.  
  78. <TextView
  79. android:id="@+id/textView5"
  80. android:textAlignment="center"
  81. android:textColor="#4267b2"
  82. android:textSize="25sp"
  83. android:layout_width="wrap_content"
  84. android:layout_height="wrap_content"
  85. android:layout_below="@+id/textView4"
  86. android:text="NearBy2"
  87. android:layout_alignParentLeft="true"
  88. android:layout_alignParentStart="true"
  89. android:layout_alignParentRight="true"
  90. android:layout_alignParentEnd="true" />
  91.  
  92. <TextView
  93. android:id="@+id/textView6"
  94. android:textAlignment="center"
  95. android:textColor="#4267b2"
  96. android:textSize="25sp"
  97. android:layout_width="wrap_content"
  98. android:layout_height="wrap_content"
  99. android:layout_alignLeft="@+id/textView5"
  100. android:layout_alignStart="@+id/textView5"
  101. android:layout_below="@+id/textView5"
  102. android:text="NearBy3"
  103. android:layout_alignParentRight="true"
  104. android:layout_alignParentEnd="true" />
  105.  
  106. <TextView
  107. android:id="@+id/textView7"
  108. android:textAlignment="center"
  109. android:textColor="#4267b2"
  110. android:textSize="25sp"
  111. android:layout_width="wrap_content"
  112. android:layout_height="wrap_content"
  113. android:layout_alignLeft="@+id/textView6"
  114. android:layout_alignStart="@+id/textView6"
  115. android:layout_below="@+id/textView6"
  116. android:text="NearBy4"
  117. android:layout_alignParentRight="true"
  118. android:layout_alignParentEnd="true" />
  119.  
  120. <TextView
  121. android:id="@+id/textView8"
  122. android:textAlignment="center"
  123. android:textColor="#4267b2"
  124. android:textSize="25sp"
  125. android:layout_width="wrap_content"
  126. android:layout_height="wrap_content"
  127. android:layout_alignLeft="@+id/textView7"
  128. android:layout_alignStart="@+id/textView7"
  129. android:layout_below="@+id/textView7"
  130. android:text="NearBy5"
  131. android:layout_alignParentRight="true"
  132. android:layout_alignParentEnd="true" />
  133.  
  134. <TextView
  135. android:id="@+id/textView9"
  136. android:textAlignment="center"
  137. android:textColor="#4267b2"
  138. android:textSize="25sp"
  139. android:layout_width="wrap_content"
  140. android:layout_height="wrap_content"
  141. android:layout_alignLeft="@+id/textView8"
  142. android:layout_alignStart="@+id/textView8"
  143. android:layout_below="@+id/textView8"
  144. android:text="NearBy6"
  145. android:layout_alignParentRight="true"
  146. android:layout_alignParentEnd="true" />
  147.  
  148. <TextView
  149. android:id="@+id/textView10"
  150. android:textAlignment="center"
  151. android:textColor="#4267b2"
  152. android:textSize="25sp"
  153. android:layout_width="wrap_content"
  154. android:layout_height="wrap_content"
  155. android:layout_alignEnd="@+id/textView9"
  156. android:layout_alignRight="@+id/textView9"
  157. android:layout_below="@+id/textView9"
  158. android:text="NearBy7"
  159. android:layout_alignParentLeft="true"
  160. android:layout_alignParentStart="true" />
  161.  
  162. <TextView
  163. android:id="@+id/textView11"
  164. android:textAlignment="center"
  165. android:textColor="#4267b2"
  166. android:textSize="25sp"
  167. android:layout_width="wrap_content"
  168. android:layout_height="wrap_content"
  169. android:layout_alignLeft="@+id/textView10"
  170. android:layout_alignStart="@+id/textView10"
  171. android:layout_below="@+id/textView10"
  172. android:text="NearBy8"
  173. android:layout_alignParentRight="true"
  174. android:layout_alignParentEnd="true" />
  175.  
  176. import android.content.Intent;
  177. import android.os.Bundle;
  178. import android.support.v7.app.AppCompatActivity;
  179. import android.view.View;
  180. import android.widget.Button;
  181. public class NearBy extends AppCompatActivity
  182. {
  183. Button BackButton;
  184. @Override
  185. protected void onCreate(Bundle savedInstanceState) {
  186. super.onCreate(savedInstanceState);
  187. setContentView(R.layout.nearby);
  188.  
  189. BackButton = (Button) findViewById(R.id.BackButton);
  190.  
  191. BackButton.setOnClickListener(new View.OnClickListener() {
  192. @Override
  193. public void onClick(View v) {
  194. Intent activity_main = new Intent(getApplicationContext(),
  195. MainActivity.class);
  196. startActivity(activity_main);
  197. }
  198. });
  199.  
  200.  
  201. }
  202. }
  203.  
  204. import android.app.Service;
  205. import android.content.Intent;
  206. import android.location.Location;
  207. import android.location.LocationListener;
  208. import android.os.Bundle;
  209. import android.os.IBinder;
  210. import android.support.annotation.Nullable;
  211. public class GPSTracker extends Service implements LocationListener {
  212. @Nullable
  213. @Override
  214. public IBinder onBind(Intent intent) {
  215.  
  216. return null;
  217. }
  218.  
  219. @Override
  220. public void onLocationChanged(Location location) {
  221.  
  222. }
  223.  
  224. @Override
  225. public void onStatusChanged(String provider, int status, Bundle extras) {
  226.  
  227. }
  228.  
  229. @Override
  230. public void onProviderEnabled(String provider) {
  231.  
  232. }
  233.  
  234. @Override
  235. public void onProviderDisabled(String provider) {
  236.  
  237. }
  238. }
  239.  
  240. protected synchronized void buildGoogleApiClient() {
  241. mGoogleApiClient = new GoogleApiClient.Builder(this)
  242. .addConnectionCallbacks(this)
  243. .addOnConnectionFailedListener(this)
  244. .addApi(LocationServices.API)
  245. .build();
  246. mGoogleApiClient.connect();
  247. }
  248.  
  249. @Override
  250. public void onConnected(@Nullable Bundle bundle) {
  251.  
  252. mLocationRequest = new LocationRequest();
  253. mLocationRequest.setInterval(15 * 1000);
  254. mLocationRequest.setFastestInterval(1000);
  255. mLocationRequest.setSmallestDisplacement(0);
  256. mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
  257.  
  258. if (ContextCompat.checkSelfPermission(this,
  259. android.Manifest.permission.ACCESS_FINE_LOCATION)
  260. == PackageManager.PERMISSION_GRANTED) {
  261. LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, locationListener);
  262. }
  263.  
  264. }
  265.  
  266. LocationListener locationListener = new LocationListener() {
  267. @Override
  268. public void onLocationChanged(Location location) {
  269. mLastLocation = location;
  270. //save the location to use it anywhere you want
  271. }
  272. }
  273. };
Add Comment
Please, Sign In to add comment