我目前正在努力改进现有的Android应用程序,该应用程序可以映射区域中不同类型的树。
从Google Play商店下载应用程序时,地图工作正常。但是,当我在Android Studios中进行操作时,它只是显示灰色屏幕。
我从谷歌获得了一个API密钥并将其放在google_maps_api.xml
中这就是我正在初始化地图的方式:
if key == ['k']:
win.clearBuffer()
win.flip()
return win, None
elif key == ['r']:
win.close()
display.init()
display.set_mode(resolution, FULLSCREEN |DOUBLEBUF,32)
pylink.openGraphics()
print 'This is a monocular calibration routine. Please select the appropriate eye.'
# set calibration colors (target, background)
pylink.setCalibrationColors((255, 255, 255), (0, 0, 0))
# set calibration target size (diameter, hole)
pylink.setTargetSize(int(0.25 * degToPix), int(0.05 * degToPix))
# set calibration sounds
pylink.setCalibrationSounds('', '', '')
pylink.setDriftCorrectSounds('', 'off', 'off')
# custom calibration routine: randomize and repeat first target must be turned off inside EYELINK
# 5 1 6
# 9 10
# 3 0 4
# 11 12
# 7 2 8
EYELINK.sendCommand('calibration_type = HV9')
EYELINK.sendCommand('generate_default_targets = NO')
EYELINK.sendCommand('calibration_targets = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d' % eyeCoordsR)
EYELINK.sendCommand('validation_targets = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d' % eyeCoordsR)
EYELINK.doTrackerSetup()
pylink.closeGraphics()
display.quit()
win = ps.visual.Window(resolution, units = 'pix', fullscr = True, screen = 1, color = (0, 0, 0), colorSpace = 'rgb255', useFBO = False)
return win, None
elif key == ['l']:
win.close()
display.init()
display.set_mode(resolution, FULLSCREEN |DOUBLEBUF,32)
pylink.openGraphics()
print 'This is a monocular calibration routine. Please select the appropriate eye.'
# set calibration colors (target, background)
pylink.setCalibrationColors((255, 255, 255), (0, 0, 0))
# set calibration target size (diameter, hole)
pylink.setTargetSize(int(0.25 * degToPix), int(0.05 * degToPix))
# set calibration sounds
pylink.setCalibrationSounds('', '', '')
pylink.setDriftCorrectSounds('', 'off', 'off')
# custom calibration routine: randomize and repeat first target must be turned off inside EYELINK
# 5 1 6
# 9 10
# 3 0 4
# 11 12
# 7 2 8
EYELINK.sendCommand('calibration_type = HV9')
EYELINK.sendCommand('generate_default_targets = NO')
EYELINK.sendCommand('calibration_targets = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d' % eyeCoordsL)
EYELINK.sendCommand('validation_targets = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d' % eyeCoordsL)
EYELINK.doTrackerSetup()
pylink.closeGraphics()
display.quit()
win = ps.visual.Window(resolution, units = 'pix', fullscr = True, screen = 1, color = (0, 0, 0), colorSpace = 'rgb255', useFBO = False)
return win, None
elif key == ['e']:
print '\t Exit? YES (Y) or NO (N)'
key = ps.event.waitKeys(keyList = ['y', 'n'])
if key == ['y']:
return win, True
elif key == ['n']:
return win, False
这些是我在AndroidManifest中使用的权限:
if (savedInstanceState != null) {
mMapFragment = (MapFragment) myFragmentManager.findFragmentByTag("map_tag");
mMapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
setUpMap();
}
});
myFragment = (ControlClass) myFragmentManager.findFragmentByTag("control_tag");
fragmentTransaction.commit();
//mMap=mMapFragment.getMap();
} else {
mMapFragment = MapFragment.newInstance();
fragmentTransaction.add(R.id.map, mMapFragment, "map_tag");
useGPS = true;
mMapFragment.setRetainInstance(true);
myFragment = new ControlClass();
fragmentTransaction.add(R.id.myfragment, myFragment, "control_tag");
fragmentTransaction.commit();
mMapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
setUpMap();
//handleNewLocation(lastKnownPosition);
}
});
}
这是我对地图活动的布局:
<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="android.permission.READ_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" />
任何帮助将不胜感激!
答案 0 :(得分:0)
事实证明,有两个版本的google_maps_api.xml,我的清单指的是调试版本,它仍然包含以前的api密钥。更改google_maps_api.xml调试版本中的密钥解决了问题。