Я сделал глобальные переменные широты и долготы.
Он отлично работает в классе MyLocationListener
, так как отображает текущую широту и долготу местоположения, но когда он загружает URL (http://maps.google.com/maps?" + "saddr="
+ currentLattitude + "," + currentLongtitude
+ "&daddr=27.11,85.11")
) в веб-представлении, онзагружает значения 0 и 0.
Почему?
public class ShowMapActivity extends Activity {
private WebView webView;
double currentLattitude;
double currentLongtitude;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
mlocListener);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://maps.google.com/maps?" + "saddr="
+ currentLattitude + "," + currentLongtitude
+ "&daddr=27.11,85.11");
}
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
currentLattitude = loc.getLatitude();
currentLongtitude = loc.getLongitude();
Toast.makeText(
getApplicationContext(),
"Latitude is: " + currentLattitude + " Longitude is: "
+ currentLongtitude,
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider)
{
Toast.makeText(getApplicationContext(),
"Gps Disabled",
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider)
{
Toast.makeText(getApplicationContext(), "Gps Enabled",
Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
}