我有两个自动完成来查找路线,我已经完成了两个位置的路线。我有起点和目的地marker.In,我设置了信息窗口来显示纬度,经度,位置,子位置,管理区域。我已经成功地显示了lat和lan.Now,我获取了Json数据并显示在信息窗口中。我已经解析了数据,但不知道如何在info window.suggest中显示它。
googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
// Use default InfoWindow frame
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
public View getInfoContents(Marker arg0) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.info_window, null);
// Getting the position from the marker
LatLng latLng = arg0.getPosition();
// Getting reference to the TextView to set latitude
TextView tvLat = (TextView) v.findViewById(R.id.tv_lat);
// Getting reference to the TextView to set longitude
TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);
TextView type=(TextView)v.findViewById(R.id.type);
// Setting the latitude
tvLat.setText("Latitude:" + latLng.latitude);
// Setting the longitude
tvLng.setText("Longitude:" + latLng.longitude);
type.setText("locality"+"");
// Returning the view containing InfoWindow contents
return v;
}
});
public void onDirectionFinderStart() {
progressDialog = ProgressDialog.show(this, "Please wait.",
"Finding direction..!", true);
if (originMarkers != null) {
for (Marker marker : originMarkers) {
marker.remove();
marker.showInfoWindow();
}
}
if (destinationMarkers != null) {
for (Marker marker : destinationMarkers) {
marker.remove();
marker.showInfoWindow();
}
}
if (polylinePaths != null) {
for (Polyline polyline : polylinePaths) {
polyline.remove();
}
}
}
private class GetLocationTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray addrComp = jsonObj.getJSONArray("results");
for (int i = 0; i < addrComp.length(); i++){
JSONObject ad=new JSONObject();
JSONArray addr = ad.getJSONArray("address_components");
for (i = 0; i < addr.length(); i++){
JSONObject ty=new JSONObject();
JSONArray typ=ty.getJSONArray("types");
for (i = 0; i < typ.length(); i++){
JSONObject c = typ.getJSONObject(i);
String locality=c.getString("locality");
String political=c.getString("political");
String sublocality=c.getString("sublocality");
String adminArea=c.getString("administrative_area_level_1");
/*HashMap<String, String> local = new HashMap<>();
local.put("locality",locality);
local.put("administrative_area_level_1",adminArea);
local.put("sublocality",sublocality);
local.put("political",political);
list.add(local);*/
}
}
}
}
catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
}
发布于 2016-07-19 19:12:16
https://stackoverflow.com/questions/38456825
复制相似问题