簡體   English   中英

Android,StreetView無法在我的設備上正確顯示Htc Desire

[英]Android,StreetView not showing correctly on my device Htc Desire

我有HTC的願望,正在嘗試編寫一個應用程序以顯示我的當前位置。

我設法編寫了應用程序並顯示了我的位置。 但是我只能在衛星視圖中看到我的位置。 當我嘗試僅獲取streetView時,地圖顯示為空白,並且根本沒有顯示街道。

這是我試圖用來顯示streetView的代碼。

public class FindMeInMap extends MapActivity {

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

  MapController mapController;
  MyPositionOverlay positionOverlay;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MapView myMapView = (MapView)findViewById(R.id.theMapView);
    myMapView.displayZoomControls(true);
    myMapView.setBuiltInZoomControls(true);
    mapController = myMapView.getController();

    myMapView.setSatellite(false);
    myMapView.setStreetView(true);
    myMapView.displayZoomControls(true);
    myMapView.setTraffic(true);





    // Add the MyPositionOverlay
    positionOverlay = new MyPositionOverlay();
    List<Overlay> overlays = myMapView.getOverlays();
    overlays.add(positionOverlay);

    LocationManager locationManager;
    String context = Context.LOCATION_SERVICE;
    locationManager = (LocationManager)getSystemService(context);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    String provider = locationManager.getBestProvider(criteria, true);

    Location location = locationManager.getLastKnownLocation(provider);

    updateWithNewLocation(location);

    locationManager.requestLocationUpdates(provider, 2000, 10,   
                                           locationListener);
  }

  private final LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      updateWithNewLocation(location);
    }

    public void onProviderDisabled(String provider){
      updateWithNewLocation(null);
    }

    public void onProviderEnabled(String provider){ }
    public void onStatusChanged(String provider, int status, 
                                Bundle extras){ }
  };

  private void updateWithNewLocation(Location location) {
    String latLongString;
    TextView myLocationText;
    myLocationText = (TextView)findViewById(R.id.myLocationText);
    String addressString = "No address found";

    if (location != null) {
         // Update my location marker
        positionOverlay.setLocation(location);

      // Update the map location.
      Double geoLat = location.getLatitude()*1E6;
      Double geoLng = location.getLongitude()*1E6;
      GeoPoint point = new GeoPoint(geoLat.intValue(), 
                                    geoLng.intValue());

      mapController.animateTo(point);
      mapController.setZoom(17);


      double lat = location.getLatitude();
      double lng = location.getLongitude();
      latLongString = "Lat:" + lat + "\nLong:" + lng;

      double latitude = location.getLatitude();
      double longitude = location.getLongitude();

      Geocoder gc = new Geocoder(this, Locale.getDefault());
      try {
        List<Address> addresses = gc.getFromLocation(latitude, 
                                                     longitude, 1);
        StringBuilder sb = new StringBuilder();
        if (addresses.size() > 0) {
          Address address = addresses.get(0);

          for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
            sb.append(address.getAddressLine(i)).append("\n");

            sb.append(address.getLocality()).append("\n");
            sb.append(address.getPostalCode()).append("\n");
            sb.append(address.getCountryName());
        }
        addressString = sb.toString();
      } catch (IOException e) {}
    } else {
      latLongString = "No location found";
    }
    myLocationText.setText("Your Current Position is:\n" + 
                           latLongString + "\n" + addressString);
  }
}

任何人都可以發現我的問題,並告訴我為什么看不到我的願望正在起作用嗎? 我在模擬器上嘗試了相同的代碼,並且可以正常工作,只是不在電話上?!?

提前致謝!

進行以下更改:

myMapView.setSatellite(false);
myMapView.setStreetView(true);
myMapView.setBuiltInZoomControls(true);
myMapView.postInvalidate();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM