Как показать места, которые находятся далеко от текущего места пользователя - PullRequest
0 голосов
/ 15 октября 2019

Я занимаюсь разработкой приложения для определения местоположения. Как отобразить места, которые находятся далеко от текущего места пользователя, и как я могу показать ближайшее место из текущего места пользователя в ответе json? У меня есть жесткий код текущего места пользователя

ниже МоегоMapsActivity.kt

class MapsActivity : AppCompatActivity(), OnMapReadyCallback {

    private lateinit var mMap: GoogleMap

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_maps)
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        val mapFragment = supportFragmentManager
                .findFragmentById(R.id.map) as SupportMapFragment
        mapFragment.getMapAsync(this)
    }

    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    override fun onMapReady(googleMap: GoogleMap) {
        mMap = googleMap

        // Add a marker in Sydney and move the camera
        val stockholm = LatLng(59.329440,  18.069124)
        mMap.addMarker(MarkerOptions().position(stockholm).title("Marker in Stockholm"))
        mMap.moveCamera(CameraUpdateFactory.newLatLng(stockholm))
    }
}

ниже activity_maps.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity" />

ниже моего ответа json

[
    {
        "id": "0x1",
        "bedrooms": 1,
        "name": "Noemia apt",
        "latitude": 59.329440,
        "longitude": 18.066045
    },
    {
        "id": "0x2",
        "bedrooms": 1,
        "name": "Thalia apt",
        "latitude": 59.332532,
        "longitude": 18.057945
    },
    {
        "id": "0x3",
        "bedrooms": 1,
        "name": "Ellie apt",
        "latitude": 59.336614,
        "longitude": 18.045800
    },
    {
        "id": "0x4",
        "bedrooms": 1,
        "name": "Katherine apt",
        "latitude": 59.357729,
        "longitude": 17.996522
    },
    {
        "id": "0x5",
        "bedrooms": 2,
        "name": "Arpine apt",
        "latitude": 59.377871,
        "longitude": 17.935983
    },
    {
        "id": "0x6",
        "bedrooms": 2,
        "name": "Georgia apt",
        "latitude": 59.324272,
        "longitude": 17.846901
    },
    {
        "id": "0x7",
        "bedrooms": 2,
        "name": "Nantia apt",
        "latitude": 59.273031,
        "longitude": 18.111009
    },
    {
        "id": "0x8",
        "bedrooms": 3,
        "name": "Suzan apt",
        "latitude": 59.177559,
        "longitude": 17.976483
    },
    {
        "id": "0x9",
        "bedrooms": 3,
        "name": "Patrick apt",
        "latitude": 59.334782,
        "longitude": 18.121982
    },
    {
        "id": "0x0",
        "bedrooms": 3,
        "name": "Mark apt",
        "latitude": 59.337375,
        "longitude": 18.110026
    }
]
...