I'm making an android app. In this app, there are markers of some hotels and when user click on the marker info window appears and it should be like following image. (This is a web application)
我正在制作一个Android应用程序。在这个应用程序中,有一些酒店的标记,当用户点击标记信息窗口时,它应该像下面的图像。 (这是一个Web应用程序)
I have a list view in my navigation drawer fragment and map fragment has the markers.
我的导航抽屉片段中有一个列表视图,地图片段有标记。
This is my code before I try to load image for the info window in MainActivity.java
.
在我尝试为MainActivity.java中的信息窗口加载图像之前,这是我的代码。
// Load Hotels
private class GetHotelTask extends AsyncTask {
@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 nameValuePairs = new ArrayList(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
Here is the listview call of hotels inside MainActivity.java
.
这是MainActivity.java内酒店的listview调用。
// 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;
I've tried adding info_window_layout.xml
and here is the code.
我已经尝试添加info_window_layout.xml,这是代码。
But, I cannot load my info window like in the image. I've tried several solutions including this and any of that didn't give me a solution.
但是,我无法像在图像中那样加载我的信息窗口。我尝试了几种解决方案,包括这个,其中任何一个都没有给我一个解决方案。
Can someone please help me with this?
有人可以帮我这个吗?
Thanks in advance. :)
提前致谢。 :)
2
Figured it out finally. :D
终于搞清楚了。 :d
Changed the info_window_layout.xml
like this.
像这样更改了info_window_layout.xml。
Then added a new class called, ManiInfoAdapter.java
然后添加了一个名为ManiInfoAdapter.java的新类
class MapInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private LayoutInflater inflater;
private Context context;
public MapInfoWindowAdapter(Context context){
inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
this.cOntext= context;
}
@Override
public View getInfoWindow(Marker marker) {
// Getting view from the layout file
View v = inflater.inflate(R.layout.info_window_layout, null);
TextView title = (TextView) v.findViewById(R.id.title);
title.setText(marker.getTitle());
TextView address = (TextView) v.findViewById(R.id.distance);
address.setText(marker.getSnippet());
ImageView iv = (ImageView) v.findViewById(R.id.markerImage);
iv.setImageResource(R.drawable.ic_attraction1);
return v;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
}
Now working as expected. :)
现在按预期工作。 :)
1
Try this code :
试试这段代码:
Marker kiel=FragmentLeft.map.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(p.getLatitude()), Double.parseDouble(p.getLongitude())))
.title(p.getEventName()).snippet(getLocationStringAddress(new LatLng(Double.parseDouble(p.getLatitude()), Double.parseDouble(p.getLongitude()))))
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.map_set_marker)));
markers.put(kiel.getId(),"http://"+strPhoto);
kiel.setInfoWindowAnchor(1.95f,0.0f);
hMarker.put(kiel,p);
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
View myCOntentView= flipscreen.this.getLayoutInflater().inflate(R.layout.custommarker, null);
TextView tvTitle = ((TextView) myContentView.findViewById(R.id.title));
tvTitle.setText(arg0.getTitle());
TextView tvSnippet = ((TextView) myContentView.findViewById(R.id.snippet));
tvSnippet.setText(arg0.getSnippet());
ImageView imgMarkerImage=(ImageView)myContentView.findViewById(R.id.imgMarkerImage);
System.out.println("List of Event Photos = " + strPhoto);
Picasso.with(flipscreen.this).load(markers.get(arg0.getId())).into(imgMarkerImage);
return myContentView;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
});
map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Iterator myVeryOwnIterator = hMarker.keySet().iterator();
while(myVeryOwnIterator.hasNext()) {
Marker key=(Marker)myVeryOwnIterator.next();
if(marker.getId().equals(key.getId())){
Event value=(Event)hMarker.get(key);
Activity_Event_Details.setEventDetails(value);
startActivity(new Intent(flipscreen.this,Activity_Event_Details.class));
}
}
}
});
1
I have tried to do the same for my app. I couldn't load images into the marker as I wanted.
我试过为我的应用做同样的事情。我无法按照我的意愿将图像加载到标记中。
So what I did was.
所以我做的是。
Created an xml layout maps_info_window_blue
创建了一个xml布局maps_info_window_blue
I included into my map layout.
我加入了我的地图布局。
For me the requirement was to have the marker info window in the center. You can set it where ever you want.
对我来说,要求是将标记信息窗口放在中心。您可以根据需要进行设置。
1
Try using info window adapter. This may help you i think.
尝试使用信息窗口适配器。这可能对你有所帮助。
mMap.setInfoWindowAdapter(setMarkerWindow());
private GoogleMap.InfoWindowAdapter setMarkerWindow() {
return new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
View myCOntentView= getLayoutInflater().inflate(
R.layout.map_info_window, null);
myContentView.setBackgroundColor(Color.TRANSPARENT);
TextView tvTitle = ((TextView) myContentView
.findViewById(R.id.title));
tvTitle.setText(marker.getTitle());
......
return myContentView;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
};
}