【问题标题】:How can I do to run faster my InfoWindows?如何使 InfoWindows 运行得更快?
【发布时间】:2014-11-28 09:23:23
【问题描述】:

大家好,我的应用程序片段中有一张地图,我想在 Infowindows 行程时间上打印,但需要几秒钟才能显示出来,因为该应用程序向 Google 地图发出 HTTP 请求并接收时间,所以如何才能在您看来,我会打开更快的信息窗口吗?谢谢。

这是我的代码:

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;
                        }

                    }

【问题讨论】:

    标签: android google-maps google-maps-markers google-maps-android-api-2 infowindow


    【解决方案1】:

    查看您的代码,似乎时间仅根据地理位置计算,没有任何外部帮助。通过询问当前位置的国家、城市和邮政编码可能涉及网络请求。 (不能 100% 确定,因为它不清楚 GPSTracker 类中的内容)由于您目前没有使用这些变量,因此您应该删除它们,您的信息窗口会显示得更快。

    【讨论】:

    • 现在我试试。我这么说是因为我想,也许我会需要它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 2018-02-11
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 2017-01-29
    相关资源
    最近更新 更多