package com.example.komunitas;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
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.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
public class Maps extends FragmentActivity{
private Marker previousMarker = null;
int jd=0;
private SupportMapFragment mapFragment;
String tkode="",tnama="",tmail="",thp="",tlati="",tlongi="",talamat="",tangkatan="",tstatus="",tgambar="";
String skodelogin="",snamalogin="",smaillogin="";
String myLati="-6.352953";
String myLongi="106.831389";
String myPosisi="UI";
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
JSONArray myJSON = null;
String ip="";
ArrayList<HashMap<String, String>> arrayList;
private static final String TAG_SUKSES = "sukses";
private static final String TAG_record = "record";
String[]arkode_anggota;
String[]artgl;
String[]aralamat;
String[]arlatitude;
String[]arlongitude;
String[]arjam;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
Intent i= this.getIntent();
myLati= i.getStringExtra("myLati");
myLongi= i.getStringExtra("myLongi");
myPosisi= i.getStringExtra("myPosisi");
skodelogin= i.getStringExtra("skodelogin");
snamalogin= i.getStringExtra("snamalogin");
smaillogin= i.getStringExtra("smaillogin");
arrayList = new ArrayList<HashMap<String, String>>();
ip=jParser.getIP();
new load().execute();
}
class load extends AsyncTask<String, String, String> {
@Override protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Maps.this);
pDialog.setMessage("Load data. Silahkan Tunggu...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(ip+"lokasi/lokasi_show.php", "GET", params);
Log.d("show: ", json.toString());
try {
int sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
myJSON = json.getJSONArray(TAG_record);
jd=myJSON.length();
arkode_anggota=new String[jd];
artgl=new String[jd];
aralamat=new String[jd];
arlatitude=new String[jd];
arlongitude=new String[jd];
arjam=new String[jd];
for (int i = 0; i < jd; i++) {
JSONObject c = myJSON.getJSONObject(i);
arkode_anggota[i]= c.getString("nama_anggota");
artgl[i]= c.getString("tgl");
aralamat[i]= c.getString("alamat");
arlatitude[i]= c.getString("latitude");
arlongitude[i]= c.getString("longitude");
arjam[i]= c.getString("jam");
}
}
}
catch (JSONException e) {e.printStackTrace();}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
setupMap();
}
});}
}
private void setupMap(){
mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maps));
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override public void onMapReady(GoogleMap map) {
double lat=-6.352953;
double lon=106.831389;
try{
lat=Double.parseDouble(myLati);
lon=Double.parseDouble(myLongi);
}
catch(Exception e){
lat=-6.352953;
lon=106.831389;
}
map.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title("Posisi Anda").snippet(myPosisi));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat,lon),10));
for(int i=0;i<jd;i++){
lat=-6.352953;
lon=106.831389;
try{
lat=Double.parseDouble(arlatitude[i]);
lon=Double.parseDouble(arlongitude[i]);
}
catch(Exception e){
lat=-6.352953;
lon=106.831389;
}
map.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title(arkode_anggota[i]).snippet(artgl[i]+" "+arjam[i]+" wib "+aralamat[i]));
}
//==============
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override public boolean onMarkerClick(Marker marker) {
String locAddress = marker.getTitle();
//fillTextViews(locAddress); if (previousMarker != null) {
previousMarker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
}
marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
previousMarker = marker;
if(locAddress.equalsIgnoreCase("Posisi Anda")){}
else{
Intent i = new Intent(getApplicationContext(), Detail_anggota.class);
i.putExtra("pk", locAddress);
i.putExtra("myLati", myLati);
i.putExtra("myLongi", myLongi);
i.putExtra("myPosisi", myPosisi);
i.putExtra("skodelogin", skodelogin);
i.putExtra("snamalogin", snamalogin);
i.putExtra("smaillogin", smaillogin);
startActivityForResult(i, 100);
}
return true;
}
});
//============== }
});
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" >
<fragment android:id="@+id/maps" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
Gradle.APP
apply plugin: 'com.android.application'
android {
compileSdkVersion 28 defaultConfig {
multiDexEnabled true applicationId "com.example.komunitas" minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }
buildTypes {
release {
minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' }
}
useLibrary 'org.apache.http.legacy'}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0-alpha1' implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1' implementation 'com.android.support:cardview-v7:28.0.0-alpha1' implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:28.0.0-alpha1' implementation 'com.android.support:multidex:1.0.1' implementation 'com.jjoe64:graphview:4.2.2'
//IMAGE LOAD implementation 'com.github.bumptech.glide:glide:3.7.0'
//CHAT UI implementation 'hani.momanii.supernova_emoji_library:supernova-emoji-library:0.0.2'
// AUTH implementation 'com.google.android.gms:play-services-auth:9.2.0' implementation 'com.google.firebase:firebase-auth:9.2.0'
//DATABASE FIREBASE,UI implementation 'com.google.firebase:firebase-database:9.2.0' implementation 'com.firebaseui:firebase-ui-database:0.4.1'
//STORAGE FIREBASE implementation 'com.google.firebase:firebase-storage:9.2.0'
//Places SERVICES implementation 'com.google.android.gms:play-services-places:9.2.0' implementation 'com.google.android.gms:play-services:9.2.0'
}
apply plugin: 'com.google.gms.google-services'
Tidak ada komentar:
Posting Komentar