I am trying to integrate my firebase database with Google Maps but I am having issues. Here is my code:
我正在尝试将我的firebase数据库与Google Maps集成,但我遇到了问题。这是我的代码:
package com.test.googlemap;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private static GoogleMap mMap;
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Firebase.setAndroidContext(this);
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);
/*if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}*/
}
/**
* 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;
UiSettings UiSettings = googleMap.getUiSettings();
UiSettings.setZoomControlsEnabled(true);
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = service.getBestProvider(criteria, true);
//Location myLocation = service.getLastKnownLocation(provider);
mMap.setMyLocationEnabled(true);
//double latitude = myLocation.getLatitude();
//double longitude = myLocation.getLongitude();
//LatLng startingPosition = new LatLng(latitude, longitude);
LatLng sydney = new LatLng(-34, 151);
createMarker();
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
private void createMarker() {
Firebase ref = new Firebase("https://shining-fire-3472.firebaseio.com/locations");
//Query queryRef = ref.orderByChild("latitude");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
markerLocation marker = userSnapshot.getValue(markerLocation.class);
Double lat = Double.parseDouble(marker.getLatitude());
Double log = Double.parseDouble(marker.getLongtitude());
LatLng latLng = new LatLng(lat, log);
mMap.addMarker(new MarkerOptions().position(latLng));
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
}
Here is the appbuild gradle:
这是appbuild gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.test.googlemap"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
}
dexOptions {
preDexLibraries = false
incremental = true;
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile files('libs/firebase-client-android-2.5.2.jar')
}
I am trying to retrieve marker location objects in order to create custom markers that will show up the Map. The project will sync but whenever I try and build an APK I get this error:
我正在尝试检索标记位置对象,以便创建将显示地图的自定义标记。该项目将同步,但每当我尝试构建APK时,我会收到此错误:
Error:Execution failed for task ':app:dexDebug'.> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\Java\jdk1.8.0_60\bin\java.exe'' finished with non-zero exit value 1
错误:任务':app:dexDebug'执行失败。> com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'C:\ Program Files(x86)\ Java \ jdk1.8.0_60 \ bin \ java.exe''以非零退出值1结束
I've tried all of the fixes from other similar questions but none have worked for me.
我尝试过其他类似问题的所有修复,但没有一个对我有用。
2 个解决方案
#1
0
- It happen because of heap size
- I have face same issue but issue is resolved .
- Please check below build.gradle/app file and do some changes in it.
- Firebase version and map version should be .
- Please check Code
-
add this two things in your gradle
在你的gradle中添加这两件事
multiDexEnabled true
-
**dexOptions { javaMaxHeapSize "4g" }*
** dexOptions {javaMaxHeapSize“4g”} *
它是因为堆大小而发生的
我面临同样的问题,但问题已经解决。
请检查以下build.gradle / app文件并对其进行一些更改。
Firebase版本和地图版本应该是。
请检查代码
*
apply plugin: 'com.android.application'
android { compileSdkVersion 25 buildToolsVersion "25.0.2"
android {compileSdkVersion 25 buildToolsVersion“25.0.2”
defaultConfig {
applicationId "com.jmtechnologies.askuscash"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' // compile 'com.android.support:multidex:1.0.0'
dependencies {compile fileTree(dir:'libs',include:['* .jar'])testCompile'junit:junit:4.12'// compile'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
// Spinner
compile 'com.jaredrummler:material-spinner:1.1.0'
//Firebase
compile 'com.google.firebase:firebase-messaging:10.0.1'
} apply plugin: 'com.google.gms.google-services'
} apply plugin:'com.google.gms.google-services'
#2
-1
Based on this page, they solved this kind of issue by using following this steps.
基于此页面,他们通过使用以下步骤解决了这类问题。
- Download & unzip the SDK. This should create a folder named Parse-1.xx.x (Parse-1.11.0 in my case)
- Move the entire folder to /apps/libs (make sure you deleted the previous Parse-*.jar file)
- Build > Rebuild project
下载并解压缩SDK。这应该创建一个名为Parse-1.xx.x的文件夹(在我的例子中为Parse-1.11.0)
将整个文件夹移动到/ apps / libs(确保删除了以前的Parse - * .jar文件)
构建>重建项目
If you have problem with bolts file you can resolve it by following this steps.
如果螺栓文件有问题,可以按照以下步骤解决。
- Go to: https://github.com/ParsePlatform/Parse-SDK-Android
- Download the jar file
- Store the downloaded jar file in the src/main/libs folder
- Then add the dependency in the build.gradle(module:app) file " compile 'com.parse:parse-android:1.11.0' " -> or whatever is the version number for the jar file.
- Sync the gradle file.
请访问:https://github.com/ParsePlatform/Parse-SDK-Android
下载jar文件
将下载的jar文件存储在src / main / libs文件夹中
然后在build.gradle(module:app)文件中添加依赖项“compile”com.parse:parse-android:1.11.0'“ - >或者jar文件的版本号。
同步gradle文件。
Also try to check the solution for this SO question.
同时尝试检查此SO问题的解决方案。
#1
0
- It happen because of heap size
- I have face same issue but issue is resolved .
- Please check below build.gradle/app file and do some changes in it.
- Firebase version and map version should be .
- Please check Code
-
add this two things in your gradle
在你的gradle中添加这两件事
multiDexEnabled true
-
**dexOptions { javaMaxHeapSize "4g" }*
** dexOptions {javaMaxHeapSize“4g”} *
它是因为堆大小而发生的
我面临同样的问题,但问题已经解决。
请检查以下build.gradle / app文件并对其进行一些更改。
Firebase版本和地图版本应该是。
请检查代码
*
apply plugin: 'com.android.application'
android { compileSdkVersion 25 buildToolsVersion "25.0.2"
android {compileSdkVersion 25 buildToolsVersion“25.0.2”
defaultConfig {
applicationId "com.jmtechnologies.askuscash"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' // compile 'com.android.support:multidex:1.0.0'
dependencies {compile fileTree(dir:'libs',include:['* .jar'])testCompile'junit:junit:4.12'// compile'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
// Spinner
compile 'com.jaredrummler:material-spinner:1.1.0'
//Firebase
compile 'com.google.firebase:firebase-messaging:10.0.1'
} apply plugin: 'com.google.gms.google-services'
} apply plugin:'com.google.gms.google-services'
#2
-1
Based on this page, they solved this kind of issue by using following this steps.
基于此页面,他们通过使用以下步骤解决了这类问题。
- Download & unzip the SDK. This should create a folder named Parse-1.xx.x (Parse-1.11.0 in my case)
- Move the entire folder to /apps/libs (make sure you deleted the previous Parse-*.jar file)
- Build > Rebuild project
下载并解压缩SDK。这应该创建一个名为Parse-1.xx.x的文件夹(在我的例子中为Parse-1.11.0)
将整个文件夹移动到/ apps / libs(确保删除了以前的Parse - * .jar文件)
构建>重建项目
If you have problem with bolts file you can resolve it by following this steps.
如果螺栓文件有问题,可以按照以下步骤解决。
- Go to: https://github.com/ParsePlatform/Parse-SDK-Android
- Download the jar file
- Store the downloaded jar file in the src/main/libs folder
- Then add the dependency in the build.gradle(module:app) file " compile 'com.parse:parse-android:1.11.0' " -> or whatever is the version number for the jar file.
- Sync the gradle file.
请访问:https://github.com/ParsePlatform/Parse-SDK-Android
下载jar文件
将下载的jar文件存储在src / main / libs文件夹中
然后在build.gradle(module:app)文件中添加依赖项“compile”com.parse:parse-android:1.11.0'“ - >或者jar文件的版本号。
同步gradle文件。
Also try to check the solution for this SO question.
同时尝试检查此SO问题的解决方案。