【发布时间】:2017-04-22 13:03:53
【问题描述】:
我正在尝试在比萨应用程序中实现谷歌我的应用程序,但它显示空白页面我该怎么办?
在我的 java 代码下面。
public class FindUsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_us);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng sydney = new LatLng(56.855776, 14.829839);
Marker DSlocation = mMap.addMarker(new MarkerOptions().position(sydney).title("Maestro restaurang &
pizzeria").snippet("Click Navigation icon below for navigation"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,18));
} }
我的xml文件
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.yodgor777.maestro.FindUsActivity" />
我的清单
<?xml version="1.0" encoding="utf-8"?> <manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yodgor777.maestro">
不需要 ACCESS_COARSE/FINE_LOCATION 权限即可使用 Google Maps Android API v2,但您必须指定粗略或精细 “我的位置”功能的位置权限。 -->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeScreenActivity"
android:label="@string/title_activity_home_screen" />
<activity android:name=".MainActivity" />
<activity android:name=".Information" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".FindUsActivity"
android:label="@string/title_activity_find_us"></activity>
</application>
</manifest>
【问题讨论】:
标签: java android google-maps