2016-05-17 11 views
0

Google Maps APIにポップアップバブルを作成しようとしています。ここに私がしたいことがあります。私がA点からB地点に向かって走っているとしましょう。地点Aから地点Bに向かう途中で、私がその特定の地域の近くにいるときに人気のある場所をポップアップバブルで表示したいと思います。 ?ありがとうGoogle Maps APIでポップアップバブルを作成する

答えて

0

現在のところ、機能やビューはありませんが、独自のカスタムメニューを簡単に作成できます。たとえば、カスタム背景を持つTextViewを作成し、それをGoogleマップの断片の上に置くだけです。

は、フラグメントの上にビューを配置するには、あなたはそうのような、そのようRelativeLayoutとして、レイアウトにフラグメントを配置する必要があります:

<RelativeLayout 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="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.akashbhave.locomoto.MapsDemo"> 

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    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="com.akashbhave.locomoto.MapsDemo" /> 

<TextView 
    android:layout_width="100dp" 
    android:layout_height="60dp" 
    android:id="@+id/infoView" 
    android:textSize="14sp" 
    android:textColor="#000000" 
    android:background="@drawable/infoViewLayout" 
    android:gravity="center_vertical|center_horizontal" 
    android:paddingRight="7dp" 
    android:paddingLeft="7dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="10dp" 
    android:layout_marginLeft="10dp"/> 
</RelativeLayout> 

その後、持っているXMLファイルを作成することができます私が上記のようにあなたの背景として設定します。
ユーザーが一般的な場所に来たときはいつでも(Javaコードで確認できます)、infoViewを表示するか、ユーザーが残しておくと表示されなくなります。例は次のようになります。

// Check distance to locations here (possible through loc1.distanceTo(loc2)) 
if(distance < targetDistance) { 
    infoView.setVisibility(View.VISIBLE); 
else { 
    infoView.setVisibility(View.INVISIBLE); 
} 

あなただけの迅速なポップアップを表示したい場合は、あなたがそうのように、Toastを使用することができます。それについてです

Toast.makeText(MapsDemo.this, "You are near" + locationName, Toast.LENGTH_LONG).show(); 

!それが役に立てば幸い!