运行我的项目后,它显示空白 map ,我采用了很多方法但现在仍然显示空白我对 map api v2 感到困惑,我的控制台不显示所有 api 版本 this is my console image it does not shows all api version
这是我的java文件
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
LocationManager locationManager;
LocationListener locationListener;
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode==1)
{
if(grantResults.length>0 && grantResults[0]==PackageManager.PERMISSION_GRANTED)
{
if(ContextCompat.checkSelfPermission(MapsActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED)
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// 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;
locationManager=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
locationListener=new LocationListener() {
@Override
public void onLocationChanged(Location location) {
LatLng myplace = new LatLng(location.getLatitude(),location.getLongitude());
mMap.addMarker(new MarkerOptions().position(myplace).title("veraval").icon(BitmapDescriptorFactory.
defaultMarker(BitmapDescriptorFactory.HUE_RED)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myplace,20));
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};
if (ContextCompat.checkSelfPermission(MapsActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
} else {
Toast.makeText(MapsActivity.this,"hello",Toast.LENGTH_LONG).show();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
}
这是我的 build.gradle 文件,我已经添加了所有依赖项,但它仍然显示空白 map
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.user.mapexample"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "google_maps_api_key", "Release_API_KEY"
}
debug{
resValue "string", "google_maps_api_key", "DEBUG_API_KEY"
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
这是我的日志
07-26 12:14:12.046 7855-7855/? I/art: Late-enabling -Xcheck:jni
07-26 12:14:12.071 7855-7862/? I/art: Debugger is no longer active
07-26 12:14:12.071 7855-7862/? I/art: Starting a blocking GC Instrumentation
07-26 12:14:12.204 7855-7855/? D/LenovoAppIconTheme:
ExtraResources;cleanCachedIcon;clear cache..
07-26 12:14:12.210 7855-7855/? W/System: ClassLoader referenced unknown path:
/data/app/com.example.user.mapsexample-1/lib/arm
07-26 12:14:12.338 7855-7855/? I/zzbz: Making Creator dynamically
07-26 12:14:12.380 7855-7855/? I/DynamiteModule: Considering local module
com.google.android.gms.maps_dynamite:0 and remote module
com.google.android.gms.maps_dynamite:220
07-26 12:14:12.380 7855-7855/? I/DynamiteModule: Selected remote version of
com.google.android.gms.maps_dynamite, version >= 220
07-26 12:14:12.404 7855-7855/? W/System: ClassLoader referenced unknown path:
07-26 12:14:12.518 7855-7855/? I/Google Maps Android API: Google Play
services client version: 12451000
07-26 12:14:12.540 7855-7855/? I/Google Maps Android API: Google Play
services package version: 12874022
07-26 12:14:13.312 7855-7855/com.example.user.mapsexample E/art: The
String#value field is not present on Android versions >= 6.0
07-26 12:14:13.690 7855-7901/com.example.user.mapsexample
D/NetworkSecurityConfig: No Network Security Config specified, using platform
default
07-26 12:14:13.709 7855-7901/com.example.user.mapsexample I/DpmTcmClient:
RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
07-26 12:14:13.930 7855-7936/com.example.user.mapsexample I/Adreno: QUALCOMM
build : 5817cca, Ie9c95840c4
Build Date
: 03/26/17
OpenGL ES
Shader Compiler Version: XE031.09.00.03
Local Branch
:
Remote Branch
: refs/tags/AU_LINUX_ANDROID_LA.UM.5.5.R1.07.00.00.269.021
Remote Branch
: NONE
Reconstruct
Branch : NOTHING
07-26 12:14:13.956 7855-7936/com.example.user.mapsexample I/OpenGLRenderer:
Initialized EGL, version 1.4
07-26 12:14:13.957 7855-7936/com.example.user.mapsexample D/OpenGLRenderer:
Swap behavior 1
07-26 12:14:14.258 7855-7866/com.example.user.mapsexample W/art: Suspending
all
threads took: 18.013ms
07-26 12:14:14.287 7855-7866/com.example.user.mapsexample I/art: Background
sticky concurrent mark sweep GC freed 7913(862KB) AllocSpace objects,
20(1612KB) LOS objects, 0% free, 13MB/13MB, paused 20.215ms total 77.392ms
07-26 12:14:14.743 7855-7866/com.example.user.mapsexample I/art: Background
sticky concurrent mark sweep GC freed 4729(195KB) AllocSpace objects, 4(2MB)
LOS objects, 9% free, 25MB/28MB, paused 5.557ms total 19.833ms
07-26 12:14:16.187 7855-7934/com.example.user.mapsexample W/DynamiteModule:
Local module descriptor class for com.google.android.gms.googlecertificates
not found.
07-26 12:14:16.199 7855-7934/com.example.user.mapsexample I/DynamiteModule:
Considering local module com.google.android.gms.googlecertificates:0 and
remote module com.google.android.gms.googlecertificates:4
07-26 12:14:16.199 7855-7934/com.example.user.mapsexample I/DynamiteModule:
Selected remote version of com.google.android.gms.googlecertificates, version
>= 4
最佳答案
build.gradle
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "google_maps_api_key", "Release_API_KEY"
}
debug {
// KL MBP debug Key
resValue "string", "google_maps_api_key", "DEBUG_API_KEY"
// KL Old Machine debug Key
// resValue "string", "google_maps_api_key", "DEBUG_API_KEY"
}
}
AndroidManifest.xml
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_api_key"/>
<uses-library
android:name="com.google.android.maps"
android:required="true" />
检查我的 answer有关如何设置 API key google_maps_api_key 并作为发布或调试添加到 build.gradle 的更多详细信息。
更新 1
设置 Google Maps API key 的简便方法。
要获得一个,请点击此链接,按照说明进行操作,然后在最后按“创建”:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r={SHA-1}%3B{YOUR_APP_PACKAGE_NAME}
例如:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=08:F2:4F:C5:43:3E:4E:B7:30:71:0F: 06:F1:9F:85:F5:E2:1D:B8:73%3Bcom.lelasoft.googlemapv2
Note: It may take up to 5 minutes for settings to take effect
更新 2
MapActivity,它在使用 Update 1 指令设置 API key 后与我一起工作,大约需要 5 分钟才能生效更新 3
更新 4
GeoLocation。build.gradle
dependencies {
// Other dependences
implementation 'com.google.android.gms:play-services-location:15.0.1' // add location dependency.
implementation 'com.google.android.gms:play-services-maps:15.0.1'
}
MapsActivity.java
@Override
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
buildGoogleApiClient();
googleApiClient.connect();
}
protected synchronized void buildGoogleApiClient() {
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
@Override
public void onLocationChanged(Location location) {
googleMap.clear();
LatLng myplace = new LatLng(location.getLatitude(), location.getLongitude());
// Add a marker in Sydney and move the camera
googleMap.addMarker(new MarkerOptions().position(myplace).title("Marker in My Current Location"));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myplace,17));
}
/**
* Enables the My Location layer if the fine mLocation permission has been granted.
*/
private void enableMyLocation() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
&& ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},REQUEST_ACCESS_FINE_LOCATION_PERMISSION);
}else if (googleApiClient != null && locationRequest !=null){
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
googleMap.setMyLocationEnabled(true);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_ACCESS_FINE_LOCATION_PERMISSION:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
enableMyLocation();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_ACCESS_FINE_LOCATION_PERMISSION){
enableMyLocation();
}
}
@Override
public void onResume() {
super.onResume();
if (googleApiClient !=null)
createLocationRequest();
}
protected void createLocationRequest() {
locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(30 * 1000);
locationRequest.setFastestInterval(5 * 1000);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
//**************************
builder.setAlwaysShow(true); //this is the key ingredient
//**************************
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(@NonNull LocationSettingsResult result) {
final Status status = result.getStatus();
final LocationSettingsStates state = result.getLocationSettingsStates();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// All mLocation settings are satisfied. The client can initialize mLocation
// requests here.
enableMyLocation();
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied. But could be fixed by showing the user
// a dialog.
try {
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
status.startResolutionForResult(MapsActivity.this, REQUEST_ACCESS_FINE_LOCATION_PERMISSION);
} catch (IntentSender.SendIntentException e) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no way to fix the
// settings so we won't show the dialog.
break;
}
}
});
}
检查完成Github Example .
关于android - 不显示谷歌 API 版本 v2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51531234/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc
如果我使用ruby版本2.5.1和Rails版本2.3.18会怎样?我有基于rails2.3.18和ruby1.9.2p320构建的rails应用程序,我只想升级ruby的版本,而不是rails,这可能吗?我必须面对哪些挑战? 最佳答案 GitHub维护apublicfork它有针对旧Rails版本的分支,有各种变化,它们一直在运行。有一段时间,他们在较新的Ruby版本上运行较旧的Rails版本,而不是最初支持的版本,因此您可能会发现一些关于需要向后移植的有用提示。不过,他们现在已经有几年没有使用2.3了,所以充其量只能让更
我安装了ruby版本管理器,并将RVM安装的ruby实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby。有没有办法让emacs像shell一样尊重ruby的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el