Android MapView显示为空

Android MapView显示为空,第1张

概述表现: <?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yu.lbs" android:versionCode="1" android:versionName="1.0" > 表现:
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.yu.lbs"    androID:versionCode="1"    androID:versionname="1.0" >    <uses-sdk        androID:minSdkVersion="8"        androID:targetSdkVersion="17" />    <uses-permission androID:name="androID.permission.INTERNET" />    <application        androID:allowBackup="true"        androID:icon="@drawable/ic_launcher"        androID:label="@string/app_name"        androID:theme="@style/Apptheme" >        <uses-library androID:name="com.Google.androID.maps" />        <activity            androID:name="com.yu.lbs.MainActivity"            androID:label="@string/app_name" >            <intent-filter>                <action androID:name="androID.intent.action.MAIN" />                <category androID:name="androID.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

main.xml中:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical" >    <com.Google.androID.maps.MapVIEw        androID:ID="@+ID/mapVIEw"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:APIKey=".........."        androID:clickable="true"        androID:enabled="true" /></linearLayout>

MainActivity.java:

import androID.os.Bundle;import androID.vIEw.Menu;import com.Google.androID.maps.MapActivity;public class MainActivity extends MapActivity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.main);    }    @OverrIDe    protected boolean isRoutedisplayed() {        // Todo auto-generated method stub        return false;    }}

活动可以开始.但是在MapVIEw中什么都没有.可以显示小网格的地图,我认为它带有MapVIEw,但没有加载地图.可能有什么不对?我使用的是Google Api v3.但是这段代码来自使用API​​ v1的教科书.

解决方法 我得到解决的方式,我不得不这样做:
final MapVIEw mapVIEw = (MapVIEw)fragmentVIEw.findVIEwByID(R.ID.map_fIEldLocation);mapVIEw.onCreate(savedInstanceState);mapVIEw.getMapAsync(new OnMapReadyCallback() {    @OverrIDe    public voID onMapReady(GoogleMap GoogleMap) {        LatLng coordinates = new LatLng(match.match.LocationLatitude,match.match.LocationLongitude);        GoogleMap.addMarker(new MarkerOptions().position(coordinates).Title(match.match.LocationAddress));        GoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates,15));        mapVIEw.onResume();    }});

我缺少的重要部分是你必须在调用getMapAsync()之前调用onCreate()方法,一旦调用了回调,你需要在MapVIEw对象上调用onResume().

这完全解决了我.

这是你自己班里的样子:

public class MainActivity extends MapActivity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.main);        if (getVIEw() != null) {            final MapVIEw mapVIEw = (MapVIEw)getVIEw().findVIEwByID(R.ID.mapVIEw);            mapVIEw.onCreate(savedInstanceState);            mapVIEw.getMapAsync(new OnMapReadyCallback() {                @OverrIDe                public voID onMapReady(GoogleMap GoogleMap) {                    LatLng coordinates = new LatLng(match.match.LocationLatitude,match.match.LocationLongitude);                    GoogleMap.addMarker(new MarkerOptions().position(coordinates).Title(match.match.LocationAddress));                    GoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates,15));                    mapVIEw.onResume();                }            }        }    }    @OverrIDe    protected boolean isRoutedisplayed() {        // Todo auto-generated method stub        return false;    }}

希望这可以帮助!

总结

以上是内存溢出为你收集整理的Android MapView显示为空全部内容,希望文章能够帮你解决Android MapView显示为空所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1138464.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存