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
試しましたすべての修正は他の似たような質問から出てきましたが、誰も私のために働いていません。
gradlewとコマンドライン上で構築し、より詳細な情報を得るために--stacktrace --debugとフラグを渡して試してみてください。 –