【发布时间】:2014-01-15 22:35:10
【问题描述】:
我知道这个问题听起来非常愚蠢和基本,但基本上,我正在使用 Google Maps API 创建一个应用程序,我有一个自定义标记出现,然后我尝试让地理编码工作,但我遇到了麻烦所以我决定去掉那部分代码并重新开始,但现在标记没有出现。
然而,我意识到,无论我如何更改代码,当我运行应用程序时,它根本不会发生变化。我已经尝试卸载它并重新安装它,关闭 Eclipse 并重新打开它,当然我也尝试过谷歌它,但我没有找到任何东西。
这是我的 MainActivity(我目前唯一的活动)的代码:
public class MainActivity extends FragmentActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
LatLng ireland = new LatLng(53.0000, -8.0000);
LatLng microsoftLatLng = new LatLng(53.276863, -6.211802);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(ireland, 6));
map.addMarker(new MarkerOptions()
.position(microsoftLatLng)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.green_briefcase_icon)));
}
}
我认为问题与我的代码无关,我认为这可能是 Eclipse 的问题,但我不明白为什么会这样。
当我运行该应用程序时,它以所需的缩放级别 (6) 聚焦于爱尔兰,并具有 GPS 位置按钮,但无论我输入的纬度和经度如何,或者我是否摆脱了“map.setMyLocationEnabled” (true)",当我再次运行它时(即使我已经先卸载了它),或者即使我将所有代码一起删除并设置内容视图,它仍然以该缩放级别显示爱尔兰并且有 GPS 定位按钮,但没有标记(但我之前有这个确切的代码完美运行)。
这是我的布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapsexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mapsexample.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBRsyLfnebJbNfteS2gcTYbTa7K2qREFm4" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
【问题讨论】:
-
发生这种情况时,通常 Project->Clean 会解决问题。
标签: android eclipse google-maps