HelloGoogleMaps - 不下载地图数据

发布于 2024-11-25 10:12:23 字数 3937 浏览 0 评论 0原文

我无法让 HelloGoogleMaps 教程(或我在另一个项目中的实现)在运行时下载地图。它在谷歌地图应用程序中工作正常,但在项目中却不行。到底是怎么回事!

Map

public class Map extends MapActivity {
List<Overlay> mapOverlays;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);

    mapView.setBuiltInZoomControls(true);
    mapView.setSatellite(true);

    mapOverlays = mapView.getOverlays();

    addLocation(1,19.240000, -99.120000, "Hhola, Mundo!", "I'm in Mexico City!");
    addLocation(2,35.410000, -139.460000, "Sekai, konichiwa!", "I'm in Japan!");

}

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

public void addLocation(int index, double latitude, double longitude, String textPrimary, String textSecondary){

    Drawable drawable = this.getResources().getDrawable(R.drawable.redmarker_a);
    if(index == 2)
        drawable = this.getResources().getDrawable(R.drawable.redmarker_b);
    else if(index == 3)
        drawable = this.getResources().getDrawable(R.drawable.palebluemarker_u);

    ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable,getApplicationContext());

    GeoPoint newPoint = new GeoPoint((int)(latitude * 1000000),(int)(longitude * 1000000));
    OverlayItem newOverlayItem = new OverlayItem(newPoint, textPrimary, textSecondary);

    itemizedoverlay.addOverlay(newOverlayItem);
    mapOverlays.add(itemizedoverlay);       
}
}

ItemizedOverlay:

public class ItemizedOverlay extends com.google.android.maps.ItemizedOverlay {

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
Context mContext;

public ItemizedOverlay(Drawable defaultMarker, Context context) {
    super(boundCenterBottom(defaultMarker));
    mContext = context;
}

@Override
protected OverlayItem createItem(int i) {
  return mOverlays.get(i);
}

@Override
public int size() {
  return mOverlays.size();
}

public void addOverlay(OverlayItem overlay) {
    mOverlays.add(overlay);
    populate();
}

@Override
protected boolean onTap(int index) {
  OverlayItem item = mOverlays.get(index);
  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
  dialog.setTitle(item.getTitle());
  dialog.setMessage(item.getSnippet());
  dialog.show();
  return true;
    }

}

Manifest

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.apl.example"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="11" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <uses-library android:name="com.google.android.maps" />
        <activity android:name=".Map"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
            <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.INTERNET" />
</manifest>

ma​​in.xml

    <?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="09e81PCxJyJXAblqt5veOmOE7Yy4-X6P5nLKi3Q"
/>

如果我转到 2.3.3 项目,此代码将有效在模拟器中。但我的设备上不是 3.0.1。

I can't get the HelloGoogleMaps tutorial (or my implementation in another project either) to download maps when its ran. It works fine in Google's Maps application, but not in the project. What is going on!

Map

public class Map extends MapActivity {
List<Overlay> mapOverlays;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);

    mapView.setBuiltInZoomControls(true);
    mapView.setSatellite(true);

    mapOverlays = mapView.getOverlays();

    addLocation(1,19.240000, -99.120000, "Hhola, Mundo!", "I'm in Mexico City!");
    addLocation(2,35.410000, -139.460000, "Sekai, konichiwa!", "I'm in Japan!");

}

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

public void addLocation(int index, double latitude, double longitude, String textPrimary, String textSecondary){

    Drawable drawable = this.getResources().getDrawable(R.drawable.redmarker_a);
    if(index == 2)
        drawable = this.getResources().getDrawable(R.drawable.redmarker_b);
    else if(index == 3)
        drawable = this.getResources().getDrawable(R.drawable.palebluemarker_u);

    ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable,getApplicationContext());

    GeoPoint newPoint = new GeoPoint((int)(latitude * 1000000),(int)(longitude * 1000000));
    OverlayItem newOverlayItem = new OverlayItem(newPoint, textPrimary, textSecondary);

    itemizedoverlay.addOverlay(newOverlayItem);
    mapOverlays.add(itemizedoverlay);       
}
}

ItemizedOverlay:

public class ItemizedOverlay extends com.google.android.maps.ItemizedOverlay {

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
Context mContext;

public ItemizedOverlay(Drawable defaultMarker, Context context) {
    super(boundCenterBottom(defaultMarker));
    mContext = context;
}

@Override
protected OverlayItem createItem(int i) {
  return mOverlays.get(i);
}

@Override
public int size() {
  return mOverlays.size();
}

public void addOverlay(OverlayItem overlay) {
    mOverlays.add(overlay);
    populate();
}

@Override
protected boolean onTap(int index) {
  OverlayItem item = mOverlays.get(index);
  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
  dialog.setTitle(item.getTitle());
  dialog.setMessage(item.getSnippet());
  dialog.show();
  return true;
    }

}

Manifest

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.apl.example"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="11" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <uses-library android:name="com.google.android.maps" />
        <activity android:name=".Map"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
            <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.INTERNET" />
</manifest>

main.xml

    <?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="09e81PCxJyJXAblqt5veOmOE7Yy4-X6P5nLKi3Q"
/>

This code works if I go to a 2.3.3 project in the emulator. But not a 3.0.1 on my device.

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

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

发布评论

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

评论(1

我不咬妳我踢妳 2024-12-02 10:12:23

还要确保您在清单中添加了互联网的使用权限,如果您在模拟器上进行测试,您需要使用 -dns 8.8.8.8 启动参数启用互联网

抱歉,我确实看到您拥有互联网的权限,但请确保您可以访问如果您使用模拟器,

还请注意,mapapi 密钥与您的“签名”文件(导出步骤,如果您在真实设备上进行测试)相关联,这意味着如果您使用 test.keystore 来创建地图 api 密钥,则创建一个新的密钥库你必须重做地图 api 密钥

also make sure ur putting uses permission for internet in your manifest and if your testing on the emulator u need to enable internet with the -dns 8.8.8.8 startup argument

sorry i do see that u have the permissions for internet but make sure u can access the web if your using the emulator

also take note that the mapapi key is tied to your "signing" file (the export step, if your testing on a real device) meaning if u used test.keystore to make your maps api key then created a new keystore you would have to redo the maps api key

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