HelloGoogleMaps - 不下载地图数据
我无法让 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>
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"
/>
如果我转到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
还要确保您在清单中添加了互联网的使用权限,如果您在模拟器上进行测试,您需要使用 -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