Adicionar uma imagem à janela de informações do marcador Android
Estou fazendo um aplicativo para Android. Neste aplicativo, existem marcadores de alguns hotéis e quando o usuário clica na janela de informações do marcador aparece e deve ser como a imagem a seguir. (Esta é uma aplicação web)
Eu tenho uma exibição de lista no fragmento da minha gaveta de navegação e o fragmento do mapa tem os marcadores.
Este é o meu código antes de tentar carregar a imagem para a janela de informações emMainActivity.java
.
// Load Hotels
private class GetHotelTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... data) {
String identifier = data[0];
// Toast.makeText(getContext(), "Manuli "+identifier, Toast.LENGTH_LONG ).show();
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://api.ayubo.lk/android/retrievehotels");
HttpResponse response = null;
String responseStr = null;
try {
//add data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("long", data[0]));
nameValuePairs.add(new BasicNameValuePair("lat", data[1]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//execute http post
response = httpclient.execute(httppost);
responseStr = EntityUtils.toString(response.getEntity());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return responseStr;
}
protected void onPostExecute(String result) {
try {
JSONArray jObj = new JSONArray(result);
for(int a=0;a<jObj.length();a++){
JSONArray obj= (JSONArray) jObj.get(a);
Log.i("json", obj.get(3).toString());
Marker marker = GoogleMapsFragment.map.addMarker(new MarkerOptions()
.position(new LatLng( Double.valueOf(obj.get(3).toString()), Double.valueOf(obj.get(2).toString())))
.title(obj.get(1).toString()+" | simple Price : "+obj.get(4).toString())
.snippet(obj.get(5).toString())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker_hotel)));
hotelMarkers.add(marker);
}
LatLng latLng = new LatLng(Double.valueOf(latitude),Double.valueOf(longtitude));
GoogleMapsFragment.map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
GoogleMapsFragment.map.animateCamera(CameraUpdateFactory.zoomTo(15));
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
}
}
Aqui está a lista de chamada de hotéis dentroMainActivity.java
.
// Hotels
case 0:
if (A == 0){
Bundle bundle = new Bundle();
bundle.putString("restaurants", "Default");
fragmentObj = new GoogleMapsFragment();
fragmentObj.setArguments(bundle);
if (!sclItems.contains(0)){
new GetHotelTask().execute(longtitude, latitude);
sclItems.add(0);
}else {
removeHotels();
sclItems.remove((Integer)0);
}
A = 1;
}else {
if (!sclItems.contains(0)){
new GetHotelTask().execute(longtitude, latitude);
sclItems.add(0);
}else {
removeHotels();
sclItems.remove((Integer)0);
}
}
break;
Eu tentei adicionarinfo_window_layout.xml
e aqui está o código.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:src="@drawable/ic_prof"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"/>
</LinearLayout>
</LinearLayout>
Mas não consigo carregar minha janela de informações como na imagem. Eu tentei várias soluções, incluindoesta e nada disso não me deu uma solução.
Alguém por favor pode me ajudar com isso?
Desde já, obrigado. :)
Erro -