The Journey of #100DaysOfCode (@henna_dev)

#Day75 of #100DaysOfCode

Today was a much better day than yesterday… I relieved myself a bit from the stress I had and the day went well… I managed to plot maps and implement a click listener in the recycler view but somehow my map is not displaying the location directly :frowning:

I am happy, I am close to finishing it :blush:

I updated my Recycler Adapter Click listener as below, this should update the activity file too…


    override fun onBindViewHolder(holder: RestaurantHolder, position: Int) {
        val restaurant = getItem(position)
        holder.bindValues(restaurant!!)

        holder.itemView.setOnClickListener {
            val intent = Intent(parent.context, MapsActivity::class.java)
            intent.putExtra("LATITUDE", restaurant.address!!.coord[0])
            intent.putExtra("LONGITUDE", restaurant.address!!.coord[1])
            parent.context.startActivity(intent)
        }
    }

The MAP Activity retrieves the value like this which is also correct

         latitude = intent.getDoubleExtra("LATITUDE", 0.0)
         longitude = intent.getDoubleExtra("LONGITUDE", 0.0)

Both latitude and longitude are global variables and are displaying the location but something is not working. It appears the correct values are not getting passed in the content extras and that’s troubling it… I will fix this tomorrow.

 override fun onMapReady(googleMap: GoogleMap) {

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

Until tomorrow

2 Likes