谷歌地图挂在低速互联网连接,Android版 [英] Google map hang in slow speed internet connection, Android

查看:214
本文介绍了谷歌地图挂在低速互联网连接,Android版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的活动之一,我显示片段谷歌地图。它的正常工作与3G或高速互联网连接。但在2G还是很慢的互联网连接它挂在我的移动,而经过一段时间后,我得到没有响应的消息。
有什么办法通过,我可以处理这种情况?

In one of my activity I am showing google map in fragment. It's working fine with 3g or high speed internet connection. But in 2g or very slow internet connection it's hang my mobile, And after some time I get 'not responding' message. Is there any way by which i can handle this situation?

这是我的工作code: -

Here is my working code:-

 public class MapLoader extends FragmentActivity implements View.OnClickListener {
  // GUI Widget
TextView lblNumber;
Button btnCall;
String number;
GoogleMap googleMap;
Bitmap myBitmap;
private String filePath;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapload);

    // Getting reference to the SupportMapFragment of activity_main.xml
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

    // Getting GoogleMap object from the fragment
    googleMap = mapFragment.getMap();
    googleMap.clear();
    String filterAddress = "";
    double lat=0;
    double lng=0;
    String ontime="";
    try {
        UserFunctions userFunction = new UserFunctions();
        JSONObject json = userFunction.getUserData(number);
        if(json.has("user")) {
            JSONArray android_version_array = json.getJSONArray("user");
            //getting android version
            for (int i = 0; i < android_version_array.length(); i++) {
                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject myObj = android_version_array.getJSONObject(i);
                String lattiude = myObj.getString("latitude");
                String logitude = myObj.getString("longitude");
                ontime=myObj.getString("gpsTime");
                lat = Double.parseDouble(lattiude);
                lng = Double.parseDouble(logitude);
                // adding each child node to HashMap key => value
            }

            Geocoder geoCoder = new Geocoder(
                    getBaseContext(), Locale.getDefault());
            try {
                List<Address> addresses = geoCoder.getFromLocation(
                        lat,
                        lng, 1);

                if (addresses.size() > 0) {
                    for (int index = 0;
                         index < addresses.get(0).getMaxAddressLineIndex(); index++)
                        filterAddress += addresses.get(0).getAddressLine(index) + " ";

                }
                //  SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
                //  mapFragment.getView().findViewById()
                TextView a = (TextView) findViewById(R.id.test);
                a.setText(filterAddress);
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (Exception e2) {
                // TODO: handle exception

                e2.printStackTrace();
            }

             // Creating an instance of MarkerOptions to set position
            MarkerOptions markerOptions = new MarkerOptions();

            LatLng LOCATION = new LatLng(lat, lng);
            // Setting position on the MarkerOptions
            markerOptions.position(LOCATION);

            // Animating to the currently touched position
            // googleMap.animateCamera(CameraUpdateFactory.newLatLng(LOCATION),17.0f);
            googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 17.0f));

            // Adding marker on the GoogleMap
            Marker marker = googleMap.addMarker(markerOptions);
            // Showing InfoWindow on the GoogleMap
            marker.showInfoWindow();

   }catch (Exception e){
        e.printStackTrace();
     }
  }
 }

请注意: - 这是不是一个完整的code。我删除了一些code出于安全原因。

NOTE:- It's not a full code. I removed some of code for security reason.

推荐答案

的GetMap()是德precated。您应该使用 getMapAsync(),避免等待在UI线程上。

getMap() is deprecated. You should use getMapAsync() and avoid to wait on the UI thread.

这篇关于谷歌地图挂在低速互联网连接,Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆