在 Android 中连接互联网时遇到问题
我正在尝试在 Android 活动的特定点访问谷歌地图。我的模拟器已连接互联网。 我还向manifest.xml 文件授予了互联网权限。但我的程序无法连接到互联网。仅显示网格线但不显示地图。我找不到任何错误。请帮助我。这是我的代码
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mv=(MapView)findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mv.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mv.displayZoomControls(true);
mc=mv.getController();
String coordinates[] = {"1.352566007", "103.78921587"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p=new GeoPoint((int)(lat*1E6),(int)(lng*1E6));
mc.animateTo(p);
mc.setZoom(17);
mv.invalidate();
我的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps"></uses-library>
<activity android:name=".geo_loc"
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>
I am trying to access google map in a specific point in a android activity. My emulator is connected with internet.
I also give internet permission to manifest.xml file. But my program can not connect to internet. Only show grid lines but no map. I can't find any error .Please help me out.here is my code
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mv=(MapView)findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mv.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mv.displayZoomControls(true);
mc=mv.getController();
String coordinates[] = {"1.352566007", "103.78921587"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p=new GeoPoint((int)(lat*1E6),(int)(lng*1E6));
mc.animateTo(p);
mc.setZoom(17);
mv.invalidate();
My manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps"></uses-library>
<activity android:name=".geo_loc"
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您很可能需要 Maps API 密钥。如果您认为您已经拥有 Maps API 密钥但仍无法弄清楚,请发布您的清单 .xml 文件
You most likely need a Maps API key. If you think you already have a Maps API key and still can't figure it out, post your manifest .xml file