Android - 在混合设置中放大,谷歌地图只显示空背景

发布于 2024-12-28 09:47:02 字数 4008 浏览 1 评论 0原文

在我的应用程序中,我显示了带有指针的谷歌地图。我已在 market 提交了该应用程序,并通过从市场下载来检查它。

默认情况下的地图显示在混合视图中。通常情况下,地图看起来不错,但当我尝试放大地图时,会显示空白背景,如下图所示 在此处输入图像描述

以下是我的地图代码:

class MapOverlay extends com.google.android.maps.Overlay {
    public boolean draw(Canvas canvas, MapView mapView,boolean shadow, long when) {
        super.draw(canvas, mapView, shadow);
        Point screenPts = new Point();

        mapView.getProjection().toPixels(p, screenPts);
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pin);            
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);         
        return true;
    }
} 

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

    Map = (ImageButton)findViewById(R.id.MapBtn);
    Hybrid = (ImageButton)findViewById(R.id.hybridBtn);

    mapView = (MapView) findViewById(R.id.mapView);
    mapView.setSatellite(true);

    mapController = mapView.getController(); 

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.getProvider(LocationManager.GPS_PROVIDER);

    Criteria criteria = new Criteria(); 
    criteria.setAccuracy(Criteria.ACCURACY_FINE); 

    String bestProvider = locationManager.getBestProvider(criteria, true);      
    p = new GeoPoint((int) (latPt * 1E6),(int) (lngPt * 1E6));

    mapController.animateTo(p);
    mapController.setZoom(16); 
    mapView.invalidate();
    mapView.setTraffic(true);
    mapController = mapView.getController();

    MapOverlay mapOverlay = new MapOverlay();
    List<Overlay> listOfOverlays = mapView.getOverlays();
    listOfOverlays.clear();
    listOfOverlays.add(mapOverlay);
}

清单:

<manifest xmlns:android="schemas.android.com/apk/res/android"; 
    package="com.app.ig.sap"
    android:versionCode="2"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:anyDensity="true"/>

    <uses-feature android:name="android.hardware.camera"/> 

    <application
        android:icon="@drawable/q_icon"
        android:theme="@android:style/Theme.Light"
        android:label="@string/app_name"
        android:debuggable="false"> 

        <uses-library android:name="com.google.android.maps" />

        <activity android:name=".SplashScreen">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.FLASHLIGHT"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

任何人都可以解释一下为什么地图在缩放时看起来像这样?

In my app I am showing a Google map with pointer. I have submitted the app in market and I checked it by downloading from the market.

The map in default is shown in Hybrid view. Normally the map looks good but when I try to zoom in the map shows an empty background as in the following figure
enter image description here

Following is my map code:

class MapOverlay extends com.google.android.maps.Overlay {
    public boolean draw(Canvas canvas, MapView mapView,boolean shadow, long when) {
        super.draw(canvas, mapView, shadow);
        Point screenPts = new Point();

        mapView.getProjection().toPixels(p, screenPts);
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pin);            
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-100, null);         
        return true;
    }
} 

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

    Map = (ImageButton)findViewById(R.id.MapBtn);
    Hybrid = (ImageButton)findViewById(R.id.hybridBtn);

    mapView = (MapView) findViewById(R.id.mapView);
    mapView.setSatellite(true);

    mapController = mapView.getController(); 

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.getProvider(LocationManager.GPS_PROVIDER);

    Criteria criteria = new Criteria(); 
    criteria.setAccuracy(Criteria.ACCURACY_FINE); 

    String bestProvider = locationManager.getBestProvider(criteria, true);      
    p = new GeoPoint((int) (latPt * 1E6),(int) (lngPt * 1E6));

    mapController.animateTo(p);
    mapController.setZoom(16); 
    mapView.invalidate();
    mapView.setTraffic(true);
    mapController = mapView.getController();

    MapOverlay mapOverlay = new MapOverlay();
    List<Overlay> listOfOverlays = mapView.getOverlays();
    listOfOverlays.clear();
    listOfOverlays.add(mapOverlay);
}

Manifest:

<manifest xmlns:android="schemas.android.com/apk/res/android"; 
    package="com.app.ig.sap"
    android:versionCode="2"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:anyDensity="true"/>

    <uses-feature android:name="android.hardware.camera"/> 

    <application
        android:icon="@drawable/q_icon"
        android:theme="@android:style/Theme.Light"
        android:label="@string/app_name"
        android:debuggable="false"> 

        <uses-library android:name="com.google.android.maps" />

        <activity android:name=".SplashScreen">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.FLASHLIGHT"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

Can anyone explain me why the map looks like this when it gets zoomed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

违心° 2025-01-04 09:47:02

Siva 根据您对我的评论的回复,这不是,因为图像在 Google 的服务器上不可用,而是由于网络延迟。图像图块加载可能会超时 - 因此,随着延迟,您会看到灰色图块(作为替代品,这至少比空白屏幕更好)。您可以调整代码来测试用户的连接,并向用户显示一条消息,通知他们连接速度较慢并且地图可能无法正确呈现。

Siva based on your reply to my comments this is not due to the imagery not being available on Google's servers, but rather to network latency. There is likely a timeout for the image tiles to load--thus with latency you're seeing the gray tiles (as substitutes, which at least is better than a blank screen). You could adapt your code to test the user's connection, and display a message to the user informing them that they have a slow connection and that the map may not render properly.

江挽川 2025-01-04 09:47:02

AFAIK 这意味着您请求的缩放级别在 Google 地图服务器上不可用,因为您请求的卫星图像在该缩放级别上不可用。

AFAIK that means that the zoom level you requested is not available on the Google Maps server, because you ask for satellite imagery which is not available at that zoom level.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文