Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#ffffff">
- <Button
- android:id="@+id/BackButton"
- android:text="Back"
- android:textColor="#FFFF"
- android:textSize="30sp"
- android:layout_width="240dp"
- android:layout_height="40dp"
- android:background="@drawable/shapecurvedrectangledarkblue"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="10dp" />
- <TextView
- android:text="Your Current Location"
- android:textAlignment="center"
- android:layout_height="30dp"
- android:textSize="25sp"
- android:textColor="#FFFFFF"
- android:background="#4267b2"
- android:id="@+id/TextView1"
- android:layout_width="match_parent"
- android:layout_marginTop="5dp"
- android:layout_alignParentTop="true"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true" />
- <TextView
- android:text="Near by bus stand/stop"
- android:layout_width="match_parent"
- android:textAlignment="center"
- android:textColor="#FFFFFF"
- android:textSize="25sp"
- android:background="#4267b2"
- android:layout_height="30dp"
- android:layout_below="@+id/TextView1"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_marginTop="40dp"
- android:id="@+id/textView" />
- <TextView
- android:id="@+id/textView3"
- android:textAlignment="center"
- android:textColor="#4267b2"
- android:textSize="25sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="CurrentLocation"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true"
- android:layout_below="@+id/TextView1" />
- <TextView
- android:id="@+id/textView4"
- android:textAlignment="center"
- android:textColor="#4267b2"
- android:textSize="25sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/textView"
- android:text="NearBy1"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true" />
- <TextView
- android:id="@+id/textView5"
- android:textAlignment="center"
- android:textColor="#4267b2"
- android:textSize="25sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/textView4"
- android:text="NearBy2"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true" />
- <TextView
- android:id="@+id/textView6"
- android:textAlignment="center"
- android:textColor="#4267b2"
- android:textSize="25sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView5"
- android:layout_alignStart="@+id/textView5"
- android:layout_below="@+id/textView5"
- android:text="NearBy3"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true" />
- <TextView
- android:id="@+id/textView7"
- android:textAlignment="center"
- android:textColor="#4267b2"
- android:textSize="25sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView6"
- android:layout_alignStart="@+id/textView6"
- android:layout_below="@+id/textView6"
- android:text="NearBy4"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true" />
- <TextView
- android:id="@+id/textView8"
- android:textAlignment="center"
- android:textColor="#4267b2"
- android:textSize="25sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView7"
- android:layout_alignStart="@+id/textView7"
- android:layout_below="@+id/textView7"
- android:text="NearBy5"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true" />
- <TextView
- android:id="@+id/textView9"
- android:textAlignment="center"
- android:textColor="#4267b2"
- android:textSize="25sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView8"
- android:layout_alignStart="@+id/textView8"
- android:layout_below="@+id/textView8"
- android:text="NearBy6"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true" />
- <TextView
- android:id="@+id/textView10"
- android:textAlignment="center"
- android:textColor="#4267b2"
- android:textSize="25sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignEnd="@+id/textView9"
- android:layout_alignRight="@+id/textView9"
- android:layout_below="@+id/textView9"
- android:text="NearBy7"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true" />
- <TextView
- android:id="@+id/textView11"
- android:textAlignment="center"
- android:textColor="#4267b2"
- android:textSize="25sp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView10"
- android:layout_alignStart="@+id/textView10"
- android:layout_below="@+id/textView10"
- android:text="NearBy8"
- android:layout_alignParentRight="true"
- android:layout_alignParentEnd="true" />
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.Button;
- public class NearBy extends AppCompatActivity
- {
- Button BackButton;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.nearby);
- BackButton = (Button) findViewById(R.id.BackButton);
- BackButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent activity_main = new Intent(getApplicationContext(),
- MainActivity.class);
- startActivity(activity_main);
- }
- });
- }
- }
- import android.app.Service;
- import android.content.Intent;
- import android.location.Location;
- import android.location.LocationListener;
- import android.os.Bundle;
- import android.os.IBinder;
- import android.support.annotation.Nullable;
- public class GPSTracker extends Service implements LocationListener {
- @Nullable
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
- @Override
- public void onLocationChanged(Location location) {
- }
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) {
- }
- @Override
- public void onProviderEnabled(String provider) {
- }
- @Override
- public void onProviderDisabled(String provider) {
- }
- }
- protected synchronized void buildGoogleApiClient() {
- mGoogleApiClient = new GoogleApiClient.Builder(this)
- .addConnectionCallbacks(this)
- .addOnConnectionFailedListener(this)
- .addApi(LocationServices.API)
- .build();
- mGoogleApiClient.connect();
- }
- @Override
- public void onConnected(@Nullable Bundle bundle) {
- mLocationRequest = new LocationRequest();
- mLocationRequest.setInterval(15 * 1000);
- mLocationRequest.setFastestInterval(1000);
- mLocationRequest.setSmallestDisplacement(0);
- mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
- if (ContextCompat.checkSelfPermission(this,
- android.Manifest.permission.ACCESS_FINE_LOCATION)
- == PackageManager.PERMISSION_GRANTED) {
- LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, locationListener);
- }
- }
- LocationListener locationListener = new LocationListener() {
- @Override
- public void onLocationChanged(Location location) {
- mLastLocation = location;
- //save the location to use it anywhere you want
- }
- }
- };
Add Comment
Please, Sign In to add comment