我的朋友和我正在制作一个涉及使用谷歌地图的手机应用程序,因此我们可以放置一旦选择就会显示信息的标记。我们遇到的问题是我们无法让谷歌地图插件工作。
我们做了以下事情: - 新增:Android支持存储库,Google Play服务,Google存储库。 - 以下内容已添加到我们的gradle模块中。
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.example.wilmar.rentacube"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
我们还使用gradle文件同步项目。但是,当我们尝试在我们的模拟器中运行它时,它说我们需要更新Google Play服务。
任何帮助将不胜感激, 提前谢谢你。:)
我们的Google地图活动中的代码符合要求:
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.example.wilmar.rentacube.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class GoogleMapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_maps);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
/**
* Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
* installed) and the map has not already been instantiated.. This will ensure that we only ever
* call {@link #setUpMap()} once when {@link #mMap} is not null.
* <p/>
* If it isn't installed {@link SupportMapFragment} (and
* {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to
* install/update the Google Play services APK on their device.
* <p/>
* A user can return to this FragmentActivity after following the prompt and correctly
* installing/updating/enabling the Google Play services. Since the FragmentActivity may not
* have been completely destroyed during this process (it is likely that it would only be
* stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this
* method in {@link #onResume()} to guarantee that it will be called.
*/
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
/**
* This is where we can add markers or lines, add listeners or move the camera. In this case, we
* just add a marker near Africa.
* <p/>
* This should only be called once and when we are sure that {@link #mMap} is not null.
*/
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
注意!:此代码由Android Studio自动生成!
答案 0 :(得分:0)
它说我们需要更新Google Play服务
嗯,Google地图是Google Play服务的一部分,应该安装在您的设备上以运行此应用程序。如果演示应用程序表示您需要更新Play服务,则表示设备上未安装Google Play服务或其版本低于应用程序所需的版本。例如。安装在设备上的Play服务的版本为6.5.11,应用程序需要7.0 - 您可以在开始时获得更新对话框 只有一个解决方案。打开Google Play Market,查找Google Play服务并将其更新到最新版本。