gpt4 book ai didi

android 谷歌地图不加载 map

转载 作者:太空狗 更新时间:2023-10-29 13:50:12 24 4
gpt4 key购买 nike

我通过谷歌搜索了这个错误,有相当多的人有同样的问题,但他们所有的解决方案都不适合我。我很想让你知道我没有在这个网站上提问的经验,所以如果你对如何改进我的问题有任何类型的反馈,它会非常欢迎。谢谢。

错误是 google map 不加载 map ,您会看到灰色屏幕和左下角的 google Logo 。

这是我的带有 map 的 java 文件:

package location.hive;

import android.app.Dialog;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.io.IOException;
import java.util.List;


public class DetailActivity extends AppCompatActivity implements OnMapReadyCallback {

private static final int DIALOG_REQUEST = 9001;

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_detail_with_map);

String city = getIntent().getStringExtra("city");

setTitle(getString(R.string.landon_hotel) + ", " + city);

Hotel hotel = DataProvider.hotelMap.get(city);
if (hotel == null) {
Toast.makeText(this, getString(R.string.error_find_hotel) + ": "
+ city, Toast.LENGTH_SHORT).show();
return;
}

TextView cityText = (TextView) findViewById(R.id.cityText);
cityText.setText(hotel.getCity());

TextView neighborhoodText = (TextView) findViewById(R.id.neighborhoodText);
neighborhoodText.setText(hotel.getNeighborhood());

TextView descText = (TextView) findViewById(R.id.descriptionText);
descText.setText(hotel.getDescription() + "\n");

if (servicesOK() && initMap()) {

Geocoder gc = new Geocoder(this);
List<Address> list;
try {
list = gc.getFromLocationName(hotel.getAddress(), 1);
Address address = list.get(0);
double lat = address.getLatitude();
double lng = address.getLongitude();
LatLng latLong = new LatLng(lat, lng);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(latLong, 5);
mMap.moveCamera(update);

MarkerOptions options = new MarkerOptions()
.title(getString(R.string.landon_hotel) + ", " + city)
.position(new LatLng(lat, lng));
mMap.addMarker(options);

} catch (IOException e) {
Toast.makeText(this, getString(R.string.error_finding_hotel), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d(this.getLocalClassName(), e.getMessage());
}

}

}

public boolean servicesOK() {
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

if (result == ConnectionResult.SUCCESS) {
return true;
} else if (GooglePlayServicesUtil.isUserRecoverableError(result)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(result, this, DIALOG_REQUEST);
dialog.show();
} else {
Toast.makeText(this, getString(R.string.error_connect_to_services), Toast.LENGTH_SHORT).show();
}
return false;
}

private boolean initMap() {
if (mMap == null) {
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMap = mapFrag.getMap();
}
return (mMap != null);
}

@Override
public void onMapReady(GoogleMap map) {
}

}

这是我的应用程序 gradle 文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationId "location.hive"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
implementation 'com.android.support:appcompat-v7:22.2.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
testImplementation 'junit:junit:4.12'
}

上面是我的gradle文件和 这是我的 Logcat 错误数据:

combinedSignalIconId=0x7f020649/com.android.systemui:drawable/stat_sys_wifi_signal_4 mobileLabel=mobily wifiLabel="HUAWEI-B315-BF2B" emergencyOnly=false combinedLabel="HUAWEI-B315-BF2B" mAirplaneMode=false mDataActivity=3 mPhoneSignalIconId=0x7f020575/com.android.systemui:drawable/stat_sys_signal_2_auto_rotate mQSPhoneSignalIconId=0x7f02015b/com.android.systemui:drawable/ic_qs_signal_2 mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x7f020575/com.android.systemui:drawable/stat_sys_signal_2_auto_rotate mDataTypeIconId=0x7f0203ef/com.android.systemui:drawable/stat_sys_data_connected_3g mQSDataTypeIconId=0x7f02015d/com.android.systemui:drawable/ic_qs_signal_3g mNoSimIconId=0x0/(null) mWifiIconId=0x7f020649/com.android.systemui:drawable/stat_sys_wifi_signal_4 mQSWifiIconId=0x7f02032b/com.android.systemui:drawable/qs_tile_wifi_signal_4 mWifiActivityIconId=0x7f0205fc/com.android.systemui:drawable/stat_sys_signal_inout mBluetoothTetherIconId=0x7f020625/com.android.systemui:drawable/stat_sys_tether_bluetooth
02-27 16:29:29.695 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:29.705 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:29.705 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:29.715 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:30.575 3059-3164/? D/com.facebook.appevents.AppEventsLogger: Got unexpected exception: java.io.WriteAbortedException: Read an exception; java.io.NotSerializableException: org.json.JSONObject
02-27 16:29:30.715 1387-1387/? D/StatusBar.NetworkController: refreshViews connected={ wifi } level=2 combinedSignalIconId=0x7f020649/com.android.systemui:drawable/stat_sys_wifi_signal_4 mobileLabel=mobily wifiLabel="HUAWEI-B315-BF2B" emergencyOnly=false combinedLabel="HUAWEI-B315-BF2B" mAirplaneMode=false mDataActivity=3 mPhoneSignalIconId=0x7f020575/com.android.systemui:drawable/stat_sys_signal_2_auto_rotate mQSPhoneSignalIconId=0x7f02015b/com.android.systemui:drawable/ic_qs_signal_2 mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x7f020575/com.android.systemui:drawable/stat_sys_signal_2_auto_rotate mDataTypeIconId=0x7f0203ef/com.android.systemui:drawable/stat_sys_data_connected_3g mQSDataTypeIconId=0x7f02015d/com.android.systemui:drawable/ic_qs_signal_3g mNoSimIconId=0x0/(null) mWifiIconId=0x7f020649/com.android.systemui:drawable/stat_sys_wifi_signal_4 mQSWifiIconId=0x7f02032b/com.android.systemui:drawable/qs_tile_wifi_signal_4 mWifiActivityIconId=0x7f02060a/com.android.systemui:drawable/stat_sys_signal_out mBluetoothTetherIconId=0x7f020625/com.android.systemui:drawable/stat_sys_tether_bluetooth
02-27 16:29:30.715 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:30.715 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:30.725 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:30.725 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:31.625 1387-1387/? D/StatusBar.NetworkController: onSignalStrengthsChanged signalStrength=SignalStrength: 6 99 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 0x2 gsm|lte level=2
02-27 16:29:31.625 1387-1387/? D/StatusBar.NetworkController: updateTelephonySignalStrength: hasService=true ss=SignalStrength: 6 99 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 -1 2147483647 0x2 gsm|lte
02-27 16:29:31.625 1387-1387/? D/StatusBar.NetworkController: updateTelephonySignalStrength: iconLevel=2
02-27 16:29:31.625 1387-1387/? D/StatusBar.NetworkController: updateTelephonySignalStrength, No signal level. mPhoneSignalIconId = com.android.systemui:drawable/stat_sys_signal_2_auto_rotate mDataSignalIconId = com.android.systemui:drawable/stat_sys_signal_2_auto_rotate mQSPhoneSignalIconId = com.android.systemui:drawable/ic_qs_signal_2 mContentDescriptionPhoneSignal = Phone two bars.
02-27 16:29:31.735 1387-1387/? D/StatusBar.NetworkController: refreshViews connected={ wifi } level=2 combinedSignalIconId=0x7f020649/com.android.systemui:drawable/stat_sys_wifi_signal_4 mobileLabel=mobily wifiLabel="HUAWEI-B315-BF2B" emergencyOnly=false combinedLabel="HUAWEI-B315-BF2B" mAirplaneMode=false mDataActivity=3 mPhoneSignalIconId=0x7f020575/com.android.systemui:drawable/stat_sys_signal_2_auto_rotate mQSPhoneSignalIconId=0x7f02015b/com.android.systemui:drawable/ic_qs_signal_2 mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x7f020575/com.android.systemui:drawable/stat_sys_signal_2_auto_rotate mDataTypeIconId=0x7f0203ef/com.android.systemui:drawable/stat_sys_data_connected_3g mQSDataTypeIconId=0x7f02015d/com.android.systemui:drawable/ic_qs_signal_3g mNoSimIconId=0x0/(null) mWifiIconId=0x7f020649/com.android.systemui:drawable/stat_sys_wifi_signal_4 mQSWifiIconId=0x7f02032b/com.android.systemui:drawable/qs_tile_wifi_signal_4 mWifiActivityIconId=0x7f0205ff/com.android.systemui:drawable/stat_sys_signal_no_inout mBluetoothTetherIconId=0x7f020625/com.android.systemui:drawable/stat_sys_tether_bluetooth
02-27 16:29:31.735 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:31.745 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:31.745 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:31.755 1387-1387/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
02-27 16:29:32.165 904-1727/? D/BatteryService: !@BatteryListener : batteryPropertiesChanged!
02-27 16:29:32.175 904-1727/? D/BatteryService: level:100, scale:100, status:2, health:2, present:true, voltage: 4387, temperature: 321, technology: Li-ion, AC powered:false, USB powered:true, POGO powered:false, Wireless powered:false, icon:17303564, invalid charger:0, maxChargingCurrent:0
02-27 16:29:32.175 904-1727/? D/BatteryService: online:4, current avg:450, charge type:1, power sharing:false, high voltage charger:false, capacity:280000, batterySWSelfDischarging:false, current_now:450
02-27 16:29:32.175 904-904/? D/BatteryService: Sending ACTION_BATTERY_CHANGED.
02-27 16:29:32.185 904-904/? I/MotionRecognitionService: Plugged
02-27 16:29:32.185 904-904/? D/MotionRecognitionService: cableConnection= 1
02-27 16:29:32.185 904-904/? D/MotionRecognitionService: setPowerConnected | current backoffstate = 1024 , state =1024
02-27 16:29:32.185 904-904/? D/MotionRecognitionService: skip setTransmitPower.
02-27 16:29:32.195 1387-1387/? D/KeyguardUpdateMonitor: received broadcast android.intent.action.BATTERY_CHANGED
02-27 16:29:32.195 1387-1387/? I/PERF: received broadcast android.intent.action.BATTERY_CHANGED
02-27 16:29:32.195 1387-1387/? D/KeyguardUpdateMonitor: handleBatteryUpdate
02-27 16:29:32.205 1800-1800/? D/CommonServiceConfiguration: getStringValueSetting
02-27 16:29:32.215 1387-1387/? D/BatteryMeterView: ACTION_BATTERY_CHANGED : level:100 status:2 health:2
02-27 16:29:32.215 1387-1387/? D/BatteryMeterView: ACTION_BATTERY_CHANGED : level:100 status:2 health:2
02-27 16:29:32.215 1387-1387/? D/BatteryMeterView: ACTION_BATTERY_CHANGED : level:100 status:2 health:2
02-27 16:29:32.235 1800-1800/? D/BatteryMonitor: new battery level: 100

最佳答案

你需要做两件事

  1. 启用 Google Android Maps API
  2. onMapReady中添加代码,并在onCreate中调用回调

如何启用 Google Android Maps API

  • https://console.developers.google.com/ 中登录您的应用
  • 单击启用 API 和服务
  • 点击 Google Maps Android API
  • 点击启用

然后将以下代码添加到您的 DetailActivity.java

public class DetailActivity extends AppCompatActivity implements OnMapReadyCallback {

private static final int DIALOG_REQUEST = 9001;

public GoogleMap mMap;

public void onMapReady(GoogleMap map) {

mMap = map;

if (servicesOK() /*&& initMap()*/) {

//Geocoder gc = new Geocoder(this);
//List<Address> list;
try {
//list = gc.getFromLocationName(hotel.getAddress(), 1);
//Address address = list.get(0);

double lat = 0.6856979;
double lng = 16.8795434;
LatLng latLong = new LatLng(lat, lng);
// CameraUpdate update = CameraUpdateFactory.newLatLngZoom(latLong, 5);
Log.i("BEGINNING","Check this");
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLong));
Log.i("Finishing","Check this");

/*MarkerOptions options = new MarkerOptions()
.title(getString(R.string.landon_hotel) + ", " + city)
.position(new LatLng(lat, lng));
mMap.addMarker(options);*/
//onMapReady(mMap);

} /*catch (IOException e) {
Toast.makeText(this, getString(R.string.error_finding_hotel), Toast.LENGTH_SHORT).show();
}*/ catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("Check this->", e.getMessage());
}



}

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_with_map);
/*
String city = getIntent().getStringExtra("city");
setTitle(getString(R.string.landon_hotel) + ", " + city);
Hotel hotel = DataProvider.hotelMap.get(city);
if (hotel == null) {
Toast.makeText(this, getString(R.string.error_find_hotel) + ": "
+ city, Toast.LENGTH_SHORT).show();
return;
}
TextView cityText = (TextView) findViewById(R.id.cityText);
cityText.setText(hotel.getCity());
TextView neighborhoodText = (TextView) findViewById(R.id.neighborhoodText);
neighborhoodText.setText(hotel.getNeighborhood());
TextView descText = (TextView) findViewById(R.id.descriptionText);
descText.setText(hotel.getDescription() + "\n");
*/


SupportMapFragment mapFrag =
(SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
// mMap = mapFrag.getMap();
mapFrag.getMapAsync(this);

}

public boolean servicesOK() {
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

if (result == ConnectionResult.SUCCESS) {
return true;
} else if (GooglePlayServicesUtil.isUserRecoverableError(result)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(result, this, DIALOG_REQUEST);
dialog.show();
} else {
Toast.makeText(this, getString(R.string.error_connect_to_services), Toast.LENGTH_LONG).show();
}
return false;
}

// private boolean initMap() {
// if (mMap == null) {
//
// }
// return (mMap != null);
// }
}

关于android 谷歌地图不加载 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49009942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com