2012-01-22 46 views
0

我尝试了每个代码和每个问题,在这里每次找到错误我都会修复一些东西 - 其他东西分解和方格框的网格覆盖所有的地图,如果我点击它,所有我需要的是而在地图上点击画出标记,并使用GPS在TextView中获得地址,这个输出看起来像this和我测试我的互联网连接仿真器和它的作品谷歌地图无法正常显示并强行关闭

这里是logcat的错误:

01-23 03:37:52.868: E/MapActivity(309): Couldn't get connection factory client 
    01-23 03:37:53.979: E/QemuSensors(309): data__poll: len=-1, errno=9: Bad file number 
    01-23 03:37:53.979: E/QemuSensors(309): data__poll: len=-1, errno=9: Bad file number 
    01-23 03:37:53.989: E/QemuSensors(309): data__poll: len=-1, errno=9: Bad file number 
    01-23 03:37:53.989: E/QemuSensors(309): data__poll: len=-1, errno=9: Bad file number 

这里代码:

public class Map extends MapActivity implements LocationListener { 

MapView map = null; 
long start; 
long end; 
MyLocationOverlay compass = null; 
MapController c; 
int x, y; 
GeoPoint g; 
Drawable d; 
LocationManager n; 
int lati = 0; 
int longi = 0; 
Customize cus; 
Drawable drawable; 
OverlayItem f; 
Location location; 
String add = ""; 
Criteria m; 

@Override 
protected void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.map); 
    map = (MapView) findViewById(R.id.mapid); 
    map.getController(); 
    map.setBuiltInZoomControls(true); 
    map.setStreetView(true); 
    map.getController().setZoom(19); 
    // map.setTraffic(true); 

    d = getResources().getDrawable(R.drawable.blue); 
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); 
    drawable = this.getResources().getDrawable(R.drawable.red); 
    drawable.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); 

    map.getOverlays().add(new Customize(d)); 
    compass = new MyLocationOverlay(Map.this, map); 
    map.getOverlays().add(compass); 

    getLastLocation(); 

} 

public void getLastLocation() { 
    String provider = getBestProvider(); 
    location = n.getLastKnownLocation(provider); 

    if (location != null) { 
     setCurrentLocation(location); 
    } else { 
     Toast.makeText(this, "Location not yet acquired", Toast.LENGTH_LONG) 
       .show(); 
    } 
    ((TextView) findViewById(R.id.providerid)).setText("Provider :" 
      + getBestProvider()); 

} 

public String getBestProvider() { 

    n = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    m = new Criteria(); 
    m.setPowerRequirement(Criteria.NO_REQUIREMENT); 
    m.setAccuracy(Criteria.NO_REQUIREMENT); 
    String bestProvider = n.getBestProvider(m, false); 
    return bestProvider; 
} 

@Override 
protected void onPause() { 
    compass.disableCompass(); 
    super.onPause(); 
    n.removeUpdates(this); 

} 

@Override 
protected void onResume() { 
    compass.enableCompass(); 
    super.onResume(); 
    n.requestLocationUpdates(getBestProvider(), 500, 1, this); 
} 

class maps extends Overlay { 
    @Override 
    public boolean onTouchEvent(MotionEvent event, MapView mapView) { 
     // ---when user lifts his finger--- 

     if (event.getAction() == 1) { 
      g = mapView.getProjection().fromPixels((int) event.getX(), 
        (int) event.getY()); 
      Geocoder geoCoder = new Geocoder(getBaseContext(), 
        Locale.getDefault()); 
      try { 
       List<Address> addresses = geoCoder.getFromLocation(
         g.getLatitudeE6()/1E6, g.getLongitudeE6()/1E6, 
         1); 

       if (addresses.size() > 0) { 
        for (int i = 0; i < addresses.get(0) 
          .getMaxAddressLineIndex(); i++) 
         add += addresses.get(0).getAddressLine(i) + "\n"; 
        ((TextView) findViewById(R.id.address)).setText(add); 

       } 

      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      return true; 
     } 
     return false; 

    } 

    /* 
    * public boolean draw(Canvas canvas, MapView mapView, boolean shadow, 
    * long when) { 
    * 
    * try{ super.draw(canvas, mapView, shadow); //---translate the GeoPoint 
    * to screen pixels--- g= new GeoPoint((int) (lati * 1E6), (int) (longi 
    * * 1E6)); Point screenPts = new Point(); 
    * mapView.getProjection().toPixels(g, screenPts); //---add the 
    * marker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), 
    * R.drawable.blue); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, 
    * null); } catch(Exception h){ 
    * 
    * h.printStackTrace(); } finally{ 
    * 
    * map.setSatellite(!map.isSatellite()); 
    * 
    * } 
    * 
    * 
    * return true; } 
    */ 

} 

@Override 
protected boolean isRouteDisplayed() { 
    return false; 
} 

public void setCurrentLocation(Location location) { 
    lati = (int) (location.getLatitude() * 1E6); 
    longi = (int) (location.getLongitude() * 1E6); 
    g = new GeoPoint(lati, longi); 

    map.getOverlays().add(new Customize(drawable)); 

} 

@Override 
public void onLocationChanged(Location arg0) { 

    setCurrentLocation(arg0); 

} 

@Override 
public void onProviderDisabled(String provider) { 
    // TODO Auto-generated method stub 
    Toast.makeText(this, "Provider Disabled", Toast.LENGTH_SHORT).show(); 

} 

@Override 
public void onProviderEnabled(String provider) { 
    // TODO Auto-generated method stub 
    Toast.makeText(this, "Provider Enabled", Toast.LENGTH_SHORT).show(); 

} 

@Override 
public void onStatusChanged(String provider, int status, Bundle extras) { 
    // TODO Auto-generated method stub 
    Toast.makeText(this, "Staus Changed", Toast.LENGTH_SHORT).show(); 

} 

private GeoPoint getPoint(double lat, double lon) { 
    return (new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0))); 
} 

public class Customize extends ItemizedOverlay<OverlayItem> { 

    ArrayList<OverlayItem> ar = new ArrayList<OverlayItem>(); 

    private Drawable defaultMarker = null; 

    public Customize(Drawable defaultMarker) { 
     super(defaultMarker); 
     this.defaultMarker = defaultMarker; 

     boundCenterBottom(defaultMarker); 

     ar.add(new OverlayItem(getPoint(40.748963847316034, 
       -73.96807193756104), "UN", "United Nations")); 
     ar.add(new OverlayItem(getPoint(40.76866299974387, 
       -73.98268461227417), "Lincoln Center", 
       "Home of Jazz at Lincoln Center")); 
     ar.add(new OverlayItem(getPoint(40.765136435316755, 
       -73.97989511489868), "Carnegie Hall", 
       "Where you go with practice, practice, practice")); 
     ar.add(new OverlayItem(getPoint(40.70686417491799, 
       -74.01572942733765), "The Downtown Club", 
       "Original home of the Heisman Trophy")); 
     ar.add(new OverlayItem(getPoint(lati, longi), " ", " ")); 

     populate(); 
    } 

    @Override 
    protected OverlayItem createItem(int i) { 
     // TODO Auto-generated method stub 
     return ar.get(i); 
    } 

    @Override 
    public int size() { 
     // TODO Auto-generated method stub 
     return ar.size(); 
    } 

    protected boolean onTap(int i) { 

     Toast.makeText(Map.this, ar.get(i).getSnippet(), Toast.LENGTH_SHORT) 
       .show(); 
     return (true); 
    } 

} 
} 

清单:

<uses-sdk android:minSdkVersion="8" /> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <uses-library android:name="com.google.android.maps"/> 
    <activity 
     android:label="@string/app_name" 
     android:name=".ShareActivity" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:label="@string/app_name" 
     android:name=".Map" > 
     <intent-filter > 
      <action android:name="com.share.MAP" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity>  
+0

你能发布'logcat'信息呢? –

+0

抱歉,但无法导入我的logcat在这里,任何身体可以帮助我,我试过evey的东西! – Weloo

+0

我在一些书中读到,当应用程序响应速度不够快(我认为它的5秒钟)时,“强制关闭”会发生。如果是这种情况,请尝试将需要大量执行时间的代码移到另一个线程中。 –

回答

0

我想通了,我的地图键错了这是造成地图不是白格出现

我需要在C盘加密钥工具的路径,是我路上这

Control Panel\All Control Panel 
Items\System\Environment Variables 

并使用cmd以克该命令等关键

keytool -list -alias androiddebugkey -keystore "Path to your debug.keystore" -storepass android -keypass android 

,最后我得到了正确的密钥:)

0

则可以尝试降低你的缩放级别...可能放大19水平不请求的位置可用...你尝试在Google地图的缩放到19级要求的位置?

如果不是这种情况,请提供更多的信息.​​.....你可以复制粘贴日志,可以给一些更多的细节......

+0

好吧@Navin我做了,我把缩放级别为13它没有给我什么黑屏,我不知道怎么回事 – Weloo

+0

什么是位置的latlng ???你尝试在谷歌地图? –

+0

我拿他们从例子来标记墨菲在安卓书籍,以在地图旁边的GPS位置标记做一些固定的标记 – Weloo