开发者

Maps loading very slowly

My app includes activity of getting coordinates of my current location and then showing the route to a destination for which i have given the coordinates.The problem is it takes hours to load the map and get the route.If anybody could suggest me how to get it done at a faster rate please.And i'm using The Map application present in mobile for getting the map functionality. Here's the code i'm using

package com.map;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

public class MapRouteActivity extends Activity {
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
    LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  LocationListener mlocListener = new MyLocationListener();
  mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
  mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);
 }


 public class MyLocationListener implements LocationListener
 {
  public void onLocationChanged(Location loc)
  {
   loc.getLatitude();
   loc.getLongitude();
   String Text = "My current location is: " + "Latitud = " + loc.getLatitude() +"Longitud = " + loc.getLongitude();
   Toast.makeText( getApplicationContext(),Text,Toast.LENGTH_SHORT).show();

   Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
     Uri.parse("http://maps.google.com/maps?saddr="+loc.getLatitude()+","+loc.getLongitude()+"&daddr=18.5204303,73.8567437"));
   startActivity(intent);
  }
  @Override
  public void onProviderDisabled(String provider)
  {
   Toast.makeText( getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT ).show();
  }
  @Override
  public void onProviderEnabled(String provider)
  {
   Toast.makeTe开发者_如何学运维xt( getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();
  }
  @Override
  public void onStatusChanged(String provider, int status, Bundle extras)
  {
  }
 }
}


GPS takes time to get a fix. It has to scan a lot of frequencies before it actually triangluates your position. The code that you have written launches Google Maps on getting a valid fix. ( on onLocationChanged() )

Instead you may use MapView. That way your map will be loaded much faster and you don't even have to wait for a proper fix.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜