0

I am trying to integrate my firebase database with Google Maps but I am having issues. Here is my code:

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:

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:

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

I've tried all of the fixes from other similar questions but none have worked for me.

kitsuto
  • 1
  • 1
  • 1

2 Answers2

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

  • multiDexEnabled true

  • **dexOptions { javaMaxHeapSize "4g" }*

*


apply plugin: 'com.android.application'

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'

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'

Yogesh Borhade
  • 694
  • 1
  • 10
  • 24
-1

Based on this page, they solved this kind of issue by using following this steps.

  1. Download & unzip the SDK. This should create a folder named Parse-1.xx.x (Parse-1.11.0 in my case)
  2. Move the entire folder to /apps/libs (make sure you deleted the previous Parse-*.jar file)
  3. Build > Rebuild project

If you have problem with bolts file you can resolve it by following this steps.

  1. Go to: https://github.com/ParsePlatform/Parse-SDK-Android
  2. Download the jar file
  3. Store the downloaded jar file in the src/main/libs folder
  4. 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.
  5. Sync the gradle file.

Also try to check the solution for this SO question.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31