我正在使用 HTC Explorer 来测试我的应用
一切都很好,直到我更改了代码以显示我当前的位置。该应用程序工作,但Logcat上记录以下错误:无法获取连接工厂客户端
这是我的MainActivity.java代码
package com.example.com.draft1;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.view.KeyEvent;
import android.widget.Toast;
import com.google.android.maps.MapController;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
public class MainActivity extends MapActivity {
private LocationManager lm;
public LocationListener locationListener;
// locationListener location =new MyLocationListener();
MapView mapView;
MapController mc;
GeoPoint p;
String coordinates[] = {"41.146064", "-80.642861"};
double lat=Double.parseDouble(coordinates[0]);
double lng=Double.parseDouble(coordinates[1]);
@Override
public void onCreate(Bundle savedInstanceState) {
lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener =new MyLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
p=new GeoPoint((int)(lat*1E6),(int)(lng*1E6));
mapView=(MapView)findViewById(R.id.mapView);
mc=mapView.getController();
mc.setCenter(p);
//mc.setZoom(13);
//mapView.invalidate();
//myMapController.setCenter(new GeoPoint((int)(lat*1E6),(int)(lng*1E6)));
}
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc) {
p=new GeoPoint((int)(loc.getLatitude()*1E6),(int)(loc.getLongitude()*1E6));
if(loc!= null) {
Toast.makeText(getBaseContext(),"Location : lat"+loc.getLatitude()+" Long "+loc.getLongitude(),Toast.LENGTH_SHORT).show();
}
mc.animateTo(p);
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider,int status,Bundle extras) {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed()
{
//adssad
return false;
}
}
为什么会发生这种情况?
任何可能的解决方案?
我真的很感激这方面的帮助
干杯!
答案 0 :(得分:0)