how to display location message in chat window same like whatsapp in android programmatically?

和自甴很熟 提交于 2019-12-03 03:46:39

Layout file :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    app:cardBackgroundColor="#e0ffc6"
    app:cardCornerRadius="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <ImageView
            android:layout_width="200dp"
            android:layout_height="150dp"
            android:padding="5dp"
            android:scaleType="fitXY"
            tools:src="@tools:sample/backgrounds/scenic" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="Location"
            android:textColor="#000000" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginRight="5dp"
            android:gravity="end"
            android:orientation="horizontal">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="11:00 AM"
                android:textColor="#000000"
                android:textSize="10sp" />

            <ImageView
                android:layout_width="10dp"
                android:layout_height="10dp"
                android:layout_gravity="center_vertical"
                tools:src="@tools:sample/avatars" />

        </LinearLayout>

    </LinearLayout>
</android.support.v7.widget.CardView>

Use this layout file as item file of recyclerview.

For map image :

Use this answer : https://stackoverflow.com/a/50674957/8089770

To get lat long and name of place :

place.getLatLng() to get the latitude and longitude

place.getName() to get Place name to show at bottom of map

For chat application demo with recyclerview can go through tutorials like :

  1. https://github.com/QuickBlox/ChatMessagesAdapter-android

  2. RecyclerView for chat app

  3. https://www.dev2qa.com/android-chat-app-example-using-recyclerview/

You can make use of static maps for that.

http://maps.googleapis.com/maps/api/staticmap?center=9.9252,78.1198&zoom=14&markers=color:blue|label:A|9.9252,78.1198&size=500x400&sensor=false

You can replace the dynamic co-ordinates programmatically like below:

String location = "http://maps.googleapis.com/maps/api/staticmap?center="
                                + Utils.CUR_LATTITUDE
                                + ","
                                + Utils.CUR_LONGITUDE
                                + "&zoom=14&markers=color:blue|label:A|"
                                + Utils.CUR_LATTITUDE
                                + ","
                                + Utils.CUR_LONGITUDE
                                + "&size=500x400&sensor=false"

follow this link google provide map thumbnail link

Also, you can get this way https://maps.googleapis.com/maps/api/staticmap?center=latitude,longitude&zoom=12&size=600x300&maptype=normal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!