大家好我在我的应用程序片段中有一张地图,我想打印Infowindows的旅行时间,但它需要几秒钟才能显示,因为该应用程序向Google地图发出HTTP请求并接收时间,所以怎么能你认为我打开更快的infowindows?谢谢。
这是我的代码:
map.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
/* Distanza a piedi e macchina sulla nuvoletta */
/***********************************************/
GPSTracker gpsTracker = new GPSTracker(MainActivity.this);
if (gpsTracker.canGetLocation() && is_online == true)
{
String stringLatitude = String.valueOf(gpsTracker.latitude);
String stringLongitude = String.valueOf(gpsTracker.longitude);
String country = gpsTracker.getCountryName(MainActivity.this);
String city = gpsTracker.getLocality(MainActivity.this);
String postalCode = gpsTracker.getPostalCode(MainActivity.this);
double currentLat = Double.parseDouble(stringLatitude);
double currentLng = Double.parseDouble(stringLongitude);
double destLat = marker.getPosition().latitude;
double destLng = marker.getPosition().longitude;
final float[] results = new float[3];
Location.distanceBetween(currentLat, currentLng, destLat, destLng, results);
float metri = results[0];
float km = Math.round((double)metri/1000);
int minuti_persona = (int)Math.round(metri/125); //125 metri al minuto -> velocità media di 2,5 m/s
int minuti_auto = (int)Math.round(km/0.7); //700 metri al minuto -> velocità media di 42 km/h
/***********************************************/
View v = getLayoutInflater().inflate(R.layout.custom_info_window, null);
TextView tvTitle = (TextView) v.findViewById(R.id.title);
TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
tvSnippet.setTypeface(tvSnippet.getTypeface(), Typeface.ITALIC); //indirizzo in corsivo
TextView tvPedonal_distance = (TextView) v.findViewById(R.id.pedonal_time);
TextView tvCar_distance = (TextView) v.findViewById(R.id.car_time);
tvTitle.setText(marker.getTitle());
tvSnippet.setText(marker.getSnippet());
if(minuti_persona <=0) // Stampa tempo per coprire la distanza
{
tvCar_distance.setText("A piedi: meno di un minuto");
}else
{
tvPedonal_distance.setText("A piedi: "+minuti_persona+ " minuti");
}
if(minuti_auto <= 0)
{
tvCar_distance.setText("In auto: meno di un minuto");
}else
{
tvCar_distance.setText("In auto: " +minuti_auto+ " minuti");
}
return v;
}else
{
View v = getLayoutInflater().inflate(R.layout.custom_info_window, null);
TextView tvTitle = (TextView) v.findViewById(R.id.title);
TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
tvTitle.setText(marker.getTitle());
tvSnippet.setText(marker.getSnippet());
return v;
}
}
答案 0 :(得分:1)
查看您的代码似乎时间仅根据地理位置计算,没有任何外部帮助。通过向国家,城市和邮政编码询问当前位置,可能涉及网络请求。 (不能100%肯定,因为它不清楚GPSTracker类中的内容)因为你目前没有使用这些变量,你应该删除它们,你的infowindow会更快出现。