Android Can';我无法让谷歌地图工作
我和我的朋友们正在开发一个手机应用程序,它涉及到谷歌地图的使用,这样我们就可以放置标记,一旦选中,就会显示信息。我们遇到的问题是,我们无法让谷歌地图插件工作 我们已经做了以下工作: -添加:Android支持存储库、Google play服务、Google存储库。 -以下内容已添加到我们的gradle模块中Android Can';我无法让谷歌地图工作,android,google-maps,android-studio,google-play-services,Android,Google Maps,Android Studio,Google Play Services,我和我的朋友们正在开发一个手机应用程序,它涉及到谷歌地图的使用,这样我们就可以放置标记,一旦选中,就会显示信息。我们遇到的问题是,我们无法让谷歌地图插件工作 我们已经做了以下工作: -添加:Android支持存储库、Google play服务、Google存储库。 -以下内容已添加到我们的gradle模块中 android { compileSdkVersion 21 buildToolsVersion '21.1.2' defaultConfig {
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服务
任何帮助都将不胜感激,
提前谢谢。:)
我们的谷歌地图活动中所需的代码:
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.os.Bundle;
导入android.support.v4.app.FragmentActivity;
导入com.example.wilmar.rentacube.R;
导入com.google.android.gms.maps.GoogleMap;
导入com.google.android.gms.maps.SupportMapFragment;
导入com.google.android.gms.maps.model.LatLng;
导入com.google.android.gms.maps.model.MarkerOptions;
公共类GoogleMapsActivity扩展了FragmentActivity{
私有GoogleMap mMap;//如果Google Play services APK不可用,则可能为空。
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u谷歌地图);
setupmapifneed();
}
@凌驾
受保护的void onResume(){
super.onResume();
setupmapifneed();
}
/**
*如果可能的话,设置地图(例如,Google Play services APK已正确启动)
*已安装)并且映射尚未实例化。这将确保
*当{@link#mMap}不为null时,调用{@link#setUpMap()}一次。
*
*如果未安装{@link SupportMapFragment}(和
*{@link com.google.android.gms.maps.MapView MapView})将提示用户
*在其设备上安装/更新Google Play services APK。
*
*用户可以按照提示正确返回此FragmentActivity
*安装/更新/启用Google Play服务。因为碎片活动可能不会
*在这一过程中被完全破坏(很可能
*停止或暂停),{@link#onCreate(Bundle)}可能不会被再次调用,因此我们应该调用它
*方法来保证将调用它。
*/
私有void setUpMapIfNeeded(){
//执行空检查以确认尚未实例化映射。
如果(mMap==null){
//尝试从SupportMapFragment获取映射。
mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
//检查我们是否成功获得地图。
如果(mMap!=null){
setUpMap();
}
}
}
/**
*在这里,我们可以添加标记或线条、添加侦听器或移动摄影机
*在非洲附近加一个标记。
*
*当我们确定{@link#mMap}不是null时,应该只调用一次。
*/
私有void setUpMap(){
mMap.addMarker(新的MarkerOptions().position(新的LatLng(0,0)).title(“Marker”);
}
}
注意!:这段代码是由Android Studio自动生成的
它说我们需要更新google play服务
嗯,谷歌地图是谷歌游戏服务的一部分,应该安装在你的设备上运行这个应用程序。如果演示应用程序说您需要更新Play服务,这意味着设备上没有安装Google Play服务,或者其版本低于应用程序的要求。例如,设备上安装的播放服务的版本为6.5.11,应用程序需要7.0-一开始就可以看到更新对话框。只有一个解决办法。打开Google Play Market,查找Google Play服务并将其更新至最新版本。是否为Google maps创建了api密钥?是的,这已创建。发布您的代码请退出:我们正在使用android studio提供给我们的Google maps活动