2016-03-31 15 views
0

firebaseデータベースとGoogleマップを統合しようとしていますが、問題が発生しています。ここに私のコードは次のとおりです。ここでGoogleマップとのAndroid firebaseの統合

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) { 

     } 
    }); 
} 
} 

は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') 

} 

私は地図を表示するカスタムマーカーを作成するために、マーカーの場所オブジェクトを取得しようとしています。このプロジェクトは同期されますが、私はこのエラーを受け取ります:

エラー: '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

試しましたすべての修正は他の似たような質問から出てきましたが、誰も私のために働いていません。

+0

gradlewとコマンドライン上で構築し、より詳細な情報を得るために--stacktrace --debugとフラグを渡して試してみてください。 –

答えて

-1

このpageに基づいて、この手順を使用してこの問題を解決しました。

  1. ダウンロード& SDKを解凍します。これで、Parse-1.xx.xという名前のフォルダが作成されるはずです
  2. フォルダ全体を/ apps/libsに移動します(前のParse - * .jarファイルを削除してください)
  3. ビルド>再構築プロジェクト

あなたはボルトに問題がある場合は、この手順に従うことによってそれを解決することができますファイル。

  1. 移動先:https://github.com/ParsePlatform/Parse-SDK-Android
  2. のsrc /メイン/ libsにフォルダ
  3. でダウンロードしたjarファイルは、次にbuild.gradle(モジュール:アプリ)に依存関係を追加
  4. ストアをjarファイルをダウンロードfile "compile" com.parse:parse-android:1.11.0 '" - >または何でもjarファイルのバージョン番号です。
  5. グラデーションファイルを同期します。

またヒープサイズ

  • の私は同じ問題に直面していますが、問題が解決されているため、それが起こる。このSO question.

  • 0
    • のためのソリューションをチェックしてみてください。
    • 下記のbuild.gradle/appファイルを確認して変更してください。
    • Firebaseのバージョンとマップのバージョンは、次のとおりです。
    • コードが
    • ** dexOptionsをmultiDexEnabled

    • あなたのGradleで、この二つのことを追加確認してください{ javaMaxHeapSize "4グラム" } *

    *


    apply plugin: 'com.android.application' 
    

    アンドロイド{ 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" 
    } 
    

    }

    依存関係{ はfileTree(DIRコンパイル: 'LIBS' が含まれます:[ '*。 jar ']) testCompile' junit:junit:4.12 ' // 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' 
    

    } プラグインを適用する:「com.google.gms.google-サービスの

    関連する問題