Rabu, 22 Juli 2020

Engine Rute Terdekat

package com.example.lp2m;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
public class Detail_wisata extends Activity {

String kodenode1A,namanode1A,kodenode1B,namanode1B;
double jarak1A,jarak1B;

int jd=64;
String[]arKode;
double[]arLati;
double[]arLongi;
double[]arJarak;
String[]arNama;
       
String myLati="-6.660531";
String myLongi="111.467079";

String myPosisi="GPS";
       
String myLati2="-6.688898";
String myLongi2="111.282493";
String myPosisi2="Tujuan Objek Wisata";



TextView txt1,txt2,txt3;
String  kategori,alamat,deskripsi, jarak,gambar,nama_wisata,latitude,longitude;
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.detail_wisata);

        Intent io = this.getIntent();
        kategori=io.getStringExtra("kategori");
        alamat=io.getStringExtra("alamat");
        deskripsi=io.getStringExtra("deskripsi");
       
        myLati2=io.getStringExtra("latitude");
        myLongi2=io.getStringExtra("longitude");
        myPosisi2=io.getStringExtra("nama_wisata");
       
        gambar=io.getStringExtra("gambar");
        jarak=io.getStringExtra("jarak");

        myLati=io.getStringExtra("myLati");
        myLongi=io.getStringExtra("myLongi");
        myPosisi=io.getStringExtra("myPosisi");
       
        nama_wisata=myPosisi2;
        latitude=myLati2;
        longitude=myLongi2;
       
        TextView txtNama=(TextView)findViewById(R.id.dnama_wisata);
        TextView txtkategori=(TextView)findViewById(R.id.dkategori);
        TextView txtAlamat=(TextView)findViewById(R.id.dalamat);
        TextView txtdeskripsi=(TextView)findViewById(R.id.ddeskripsi);
        TextView txtPosisi=(TextView)findViewById(R.id.dposisi);
        TextView txtJarak=(TextView)findViewById(R.id.djarak);txtJarak.setVisibility(View.GONE);
       
       
        txt1=(TextView)findViewById(R.id.dlintasan);
        txt2=(TextView)findViewById(R.id.djaraknya);
        txt3=(TextView)findViewById(R.id.dketerangan);
       
        ImageView myGambar=(ImageView)findViewById(R.id.myGambar);
        int gb=R.drawable.wstsejarah ;
        if(nama_wisata.equalsIgnoreCase("Pantai Dampo Awang Rembang")){gb=R.drawable.pantai_dampoawang;}
       
        else         if(nama_wisata.equalsIgnoreCase("Pantai Nyamplung")){gb=R.drawable.pantai_nyamplung;}
        else         if(nama_wisata.equalsIgnoreCase("Pantai Karang Jahe")){gb=R.drawable.karang_jahe;}
        else         if(nama_wisata.equalsIgnoreCase("Pantai Jatisari")){gb=R.drawable.pantai_jatisari;}
        else         if(nama_wisata.equalsIgnoreCase("Pantai Pasir Putih Wates")){gb=R.drawable.pasir_putih_wates;}
        else         if(nama_wisata.equalsIgnoreCase("Hutan Mangrove")){gb=R.drawable.hutan_mangrove;}
        else         if(nama_wisata.equalsIgnoreCase("Pantai Caruban")){gb=R.drawable.pantai_caruban;}
        else         if(nama_wisata.equalsIgnoreCase("Gunung Kajar")){gb=R.drawable.gunung_kajar;}
        else         if(nama_wisata.equalsIgnoreCase("Air Terjun Pasucen")){gb=R.drawable.air_terjun_pasucen;}
        else         if(nama_wisata.equalsIgnoreCase("Watu Congol")){gb=R.drawable.watu_congol;}
        else         if(nama_wisata.equalsIgnoreCase("Karangsari Park")){gb=R.drawable.karangsari_park;}
        else         if(nama_wisata.equalsIgnoreCase("De Kampoeng")){gb=R.drawable.de_kampoeng1;}
        else         if(nama_wisata.equalsIgnoreCase("Embung Lodan")){gb=R.drawable.embung_lodan;}
        else         if(nama_wisata.equalsIgnoreCase("Waduk Panohan")){gb=R.drawable.waduk_panohan;}
        else         if(nama_wisata.equalsIgnoreCase("Sumber Semen")){gb=R.drawable.sumber_semen;}
        else         if(nama_wisata.equalsIgnoreCase("Wana Wisata Kartini Mantingan")){gb=R.drawable.kartini_mantingan;}
        else         if(nama_wisata.equalsIgnoreCase("Museum RA Kartini")){gb=R.drawable.museum_ra_kartini;}
        else         if(nama_wisata.equalsIgnoreCase("Vihara Ratanavana Arama")){gb=R.drawable.vihara_ratanavana_arama;}
        else         if(nama_wisata.equalsIgnoreCase("Klenteng Cu An Kiong Lasem")){gb=R.drawable.klenteng_cu_an_kiong;}
        else         if(nama_wisata.equalsIgnoreCase("Klenteng Tjoe Hwie Kiong")){gb=R.drawable.klenteng_tjoe_hwie_kiong;}
        else         if(nama_wisata.equalsIgnoreCase("Petilasan Sunan Bonang Lasem")){gb=R.drawable.pasujudan_sunan_bonang;}
        else         if(nama_wisata.equalsIgnoreCase("Makam RA Kartini")){gb=R.drawable.makam_ra_kartini;}
        else         if(nama_wisata.equalsIgnoreCase("Kuliner Lontong Tuyuhan")){gb=R.drawable.kuliner_tuyuhan;}
        else         if(nama_wisata.equalsIgnoreCase("Sate Serepeh")){gb=R.drawable.sate_serepeh;}
        else if(nama_wisata.equalsIgnoreCase("Kelo Mrico")){gb=R.drawable.sayur_mrico;}
        else if(nama_wisata.equalsIgnoreCase("Sayur Mangut")){gb=R.drawable.sayur_mangut;}
        else if(nama_wisata.equalsIgnoreCase("Toko Kawista Dewa Burung")){gb=R.drawable.dewa_burung;}
        else if(nama_wisata.equalsIgnoreCase("Rumah Makan Praukuno")){gb=R.drawable.rm_praukuno;}
        else if(nama_wisata.equalsIgnoreCase("Rumah Makan Bu Joyo")){gb=R.drawable.rm_bu_joyo;}
        else if(nama_wisata.equalsIgnoreCase("Rumah Makan Hien")){gb=R.drawable.rm_hien;}
        else if(nama_wisata.equalsIgnoreCase("Rumah Makan Pondok Hijau")){gb=R.drawable.rm_pondok_hijau;}
        else if(nama_wisata.equalsIgnoreCase("Dokar")){gb=R.drawable.dokar;}
        else if(nama_wisata.equalsIgnoreCase("Tossa")){gb=R.drawable.tossa;}
        else if(nama_wisata.equalsIgnoreCase("Angkutan Umum")){gb=R.drawable.angkot_kuning;}
        else if(nama_wisata.equalsIgnoreCase("Terminal Rembang")){gb=R.drawable.terminal_rembang;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Pantura")){gb=R.drawable.hotel_pantura;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Antika")){gb=R.drawable.hotel_antika;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Kartini")){gb=R.drawable.hotel_kartini2;}
        else if(nama_wisata.equalsIgnoreCase("Hotel SPBU Gajah Mada")){gb=R.drawable.hotel_spbu_gajahmada;}
        else if(nama_wisata.equalsIgnoreCase("Fave Hotel")){gb=R.drawable.favehotel;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Larasati")){gb=R.drawable.hotel_larasati;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Kencana")){gb=R.drawable.hotel_kencana1;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Puri Indah")){gb=R.drawable.hotel_puri_indah;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Kencana")){gb=R.drawable.hotel_kencana1;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Rantina")){gb=R.drawable.hotel_rantina;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Sumber Agung")){gb=R.drawable.hotel_sumberagung;}
        else if(nama_wisata.equalsIgnoreCase("Hotel Surya Lasem")){gb=R.drawable.hotel_surya;}
        else if(nama_wisata.equalsIgnoreCase("PO Madu Kismo")){gb=R.drawable.bis_madukismo;}
        else if(nama_wisata.equalsIgnoreCase("PO Subur Jaya")){gb=R.drawable.bis_suburjaya;}
        else{ gb=R.drawable.ic_launcher;}
     
     

        myGambar.setImageResource(gb);
     
        txtNama.setText(nama_wisata);
        txtkategori.setText(kategori);
        txtAlamat.setText(alamat);
        txtdeskripsi.setText(deskripsi);
       // txtKoordinat.setText(latitude+","+longitude);
        txtPosisi.setText(myPosisi);
        txtJarak.setText(jarak+"km");
       
        txtJarak.setVisibility(View.GONE);

    Button  btnarah=(Button)findViewById(R.id.btnarah);
    btnarah.setOnClickListener(new View.OnClickListener() {
    public void onClick(View arg0) {
// String modeDirection = "driving";
// String url = "http://maps.google.com/maps?saddr="+myLati+","+myLongi+"&daddr="+latitude+","+longitude+"&directionsmode=" + modeDirection;
// Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
// intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
// startActivity(intent);

    String url=txt3.getText().toString();
    cetak(url);
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
    //intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
    startActivity(intent);
   
        }}); 
       
   
//     Button   call=(Button)findViewById(R.id.btncall);
//        call.setOnClickListener(new View.OnClickListener() {
//        public void onClick(View arg0) {
//        String toDial="0902234567560";
//          startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse(toDial)));
//    }});
       
   
   
   
   
    init();
        start();
        mulai();
       
    }
 
public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
         finish();
                return true;
        }
    return super.onKeyDown(keyCode, event);



void start(){
       
       
double mlati=Double.parseDouble(myLati);
double mlongi=Double.parseDouble(myLongi);

double mlati2=Double.parseDouble(myLati2);
double mlongi2=Double.parseDouble(myLongi2);


double jmaxA=1000000000;
int indexA=0;
for(int i=0;i<jd;i++){
    double r=0;
    try{
        r=getJarak(mlati,mlongi,arLati[i],arLongi[i]);
        arJarak[i]=r;
        if(r<jmaxA){
            jmaxA=r;
            indexA=i;
        }
    }
    catch(Exception ee){}
}

double jmaxB=1000000000;
int indexB=0;
for(int i=0;i<jd;i++){
    double r=0;
    try{
        r=getJarak(mlati2,mlongi2,arLati[i],arLongi[i]);
        arJarak[i]=r;
        if(r<jmaxB){
            jmaxB=r;
            indexB=i;
        }
    }
    catch(Exception ee){}
}


 kodenode1A=arKode[indexA];
 namanode1A=arNama[indexA];
 jarak1A=arJarak[indexA];

 kodenode1B=arKode[indexB];
 namanode1B=arNama[indexB];
 jarak1B=arJarak[indexB];
//==========================     

}               
       
 void mulai() {
        Node A = new Node("Wates",0);
        Node B = new Node("Jl. Nasional 1",0);
        Node C = new Node("Jl. Nasional 2",0);
        Node D = new Node("Jl. Nasional 3",0);
        Node E = new Node("Magersari",0);
        Node F = new Node("Jl. Diponegoro",0);
        Node G = new Node("Jl. Dr. Wahidin",0);
        Node H = new Node("Jl. KS Tubun",0);
        Node I = new Node("Jl. KS Tubun2",0);
        Node J = new Node("Jl. KS Tubun3",0);
        Node K = new Node("Jl. Diponegoro2",0);
        Node L = new Node("Jl. Airlangga",0);
        Node M = new Node("Jl. Yos Sudarso",0);
        Node N = new Node("Jl. Yos Sudarso2",0);
        Node O = new Node("Jl. MH Tamrin",0);
        Node P = new Node("Jl. Dr. Wahidin2",0);
        Node Q = new Node("Jl. Diponegoro3",0);
        Node R = new Node("Jl. Diponegoro4",0);
        Node S = new Node("Jl. RA Kartini",0);
        Node T = new Node("Jl. RA Kartini2",0);
        Node U = new Node("Jl. Pemuda",0);
        Node V = new Node("Jl. Slamet Riyadi",0);
        Node W = new Node("Jl. Slamet Riyadi2",0);
        Node X = new Node("Jl. Lingkar",0);
        Node Y = new Node("Jl. Landoh",0);
        Node Z = new Node("Jl. Landoh2",0);
        Node A1 = new Node("Seren",0);
        Node B1 = new Node("Jl. Blora",0);
        Node C1 = new Node("Panohan",0);
        Node D1 = new Node("Jl. Blora2",0);
        Node E1 = new Node("Jl. Blora3",0);
        Node F1 = new Node("Jl. Blora4",0);
        Node G1 = new Node("Pasucen",0);
        Node H1 = new Node("Kutoharjo",0);
        Node I1 = new Node("Kutoharjo2",0);
        Node J1 = new Node("Kutoharjo3",0);
        Node K1 = new Node("Kabongan",0);
        Node L1 = new Node("Pasarbanggi",0);
        Node M1 = new Node("Tritunggal",0);
        Node N1 = new Node("Tritunggal2",0);
        Node O1 = new Node("Punjulharjo",0);
        Node P1 = new Node("Punjulharjo2",0);
        Node Q1 = new Node("Karangpelem",0);
        Node R1 = new Node("Karangpelem2",0);
        Node S1 = new Node("Gedongmulyo",0);
        Node T1 = new Node("Karangturi",0);
        Node U1 = new Node("Karangturi2",0);
        Node V1 = new Node("Karangturi3",0);
        Node W1 = new Node("Jl. Provinsi",0);
        Node X1 = new Node("Jl. Provinsi2",0);
        Node Y1 = new Node("Jl. Japerejo",0);
        Node Z1 = new Node("Jl. Gunem",0);
        Node A2 = new Node("Jl. Pamotan",0);
        Node B2 = new Node("Sale",0);
        Node C2 = new Node("Sale2",0);
        Node D2 = new Node("Jl. Kragan",0);
        Node E2 = new Node("Bonang",0);
        Node F2 = new Node("Jatisari",0);
        Node G2 = new Node("Jl. Baidhowi",0);
        Node H2 = new Node("Jl. Baidhowi2",0);
        Node I2 = new Node("Kajar",0);
        Node J2 = new Node("Selopuro",0);
        Node K2 = new Node("Vihara",0);
       
       
        //JARAK SATUAN KM
        A.connect(new Edge(B,0.55));
        B.connect(new Edge(A,0.55));
       
        B.connect(new Edge(C,3.3));
        C.connect(new Edge(B,3.3));
       
        C.connect(new Edge(D,0.21));
        D.connect(new Edge(C,0.21));
       
        D.connect(new Edge(E,1.2));
        E.connect(new Edge(D,1.2));
       
        E.connect(new Edge(F,1));
        F.connect(new Edge(E,1));
       
        F.connect(new Edge(G,0.3));
        G.connect(new Edge(F,0.3));
        F.connect(new Edge(K,0.5));
        K.connect(new Edge(F,0.5));
       
        G.connect(new Edge(H,0.19));
        G.connect(new Edge(L,0.29));
        G.connect(new Edge(P,0.2));
        H.connect(new Edge(G,0.19));
        L.connect(new Edge(G,0.29));
        P.connect(new Edge(G,0.2));
       
        I.connect(new Edge(J,0.6));
        I.connect(new Edge(N,0.5));
        I.connect(new Edge(V,0.95));
        J.connect(new Edge(I,0.6));
        N.connect(new Edge(I,0.5));
        V.connect(new Edge(I,0.95));
       
        K.connect(new Edge(P,0.16));
        K.connect(new Edge(Q,0.24));
        P.connect(new Edge(K,0.16));
        Q.connect(new Edge(K,0.24));
       
        H.connect(new Edge(M,0.5));
        M.connect(new Edge(H,0.5));
       
       
       
        M.connect(new Edge(N,0.12));
        M.connect(new Edge(O,0.15));
        M.connect(new Edge(T,0.35));
        N.connect(new Edge(M,0.12));
        O.connect(new Edge(M,0.15));
        T.connect(new Edge(M,0.35));
       
        L.connect(new Edge(P,0.11));
        L.connect(new Edge(O,0.25));
        P.connect(new Edge(L,0.11));
        O.connect(new Edge(L,0.25));
       
        O.connect(new Edge(Q,0.35));
        Q.connect(new Edge(O,0.35));
               
        Q.connect(new Edge(R,0.3));
        R.connect(new Edge(Q,0.3));
       
        P.connect(new Edge(S,0.3));
        S.connect(new Edge(P,0.3));
       
        R.connect(new Edge(S,0.27));
        R.connect(new Edge(H1,0.7));
        S.connect(new Edge(R,0.27));
        H1.connect(new Edge(R,0.7));
       
        S.connect(new Edge(U,0.29));
        U.connect(new Edge(S,0.29));
       
        T.connect(new Edge(U,0.11));
        U.connect(new Edge(T,0.11));
       
        N.connect(new Edge(U,0.45));
        U.connect(new Edge(N,0.45));
       
        U.connect(new Edge(V,0.11));
        U.connect(new Edge(X,0.29));
        V.connect(new Edge(U,0.11));
        X.connect(new Edge(U,0.29));
             
        V.connect(new Edge(W,2.2));
        W.connect(new Edge(V,2.2));
       
        W.connect(new Edge(X,1));
        X.connect(new Edge(W,1));
       
        X.connect(new Edge(Y,5));
        Y.connect(new Edge(X,5));
       
        Y.connect(new Edge(Z,4.6));
        Y.connect(new Edge(B1,5.4));
        Z.connect(new Edge(Y,4.6));
        B1.connect(new Edge(Y,5.4));
       
        Z.connect(new Edge(A1,3.7));
        A1.connect(new Edge(Z,3.7));
       
        B1.connect(new Edge(C1,6.8));
        B1.connect(new Edge(D1,6.1));
        C1.connect(new Edge(B1,6.8));
        D1.connect(new Edge(B1,6.1));
       
        D1.connect(new Edge(E1,2.8));
        E1.connect(new Edge(D1,2.8));
       
        E1.connect(new Edge(F1,0.95));
        F1.connect(new Edge(E1,0.95));
       
        F1.connect(new Edge(G1,6.8));
        G1.connect(new Edge(F1,6.8));
       
        H1.connect(new Edge(I1,0.22));
        I1.connect(new Edge(H1,0.22));
       
        I1.connect(new Edge(J1,0.1));
        I1.connect(new Edge(K1,1.1));
        J1.connect(new Edge(I1,0.1));
        K1.connect(new Edge(I1,1.1));
       
        K1.connect(new Edge(L1,3.1));
        L1.connect(new Edge(K1,3.1));
       
        L1.connect(new Edge(M1,1.4));
        M1.connect(new Edge(L1,1.4));
       
        M1.connect(new Edge(N1,0.9));
        N1.connect(new Edge(M1,0.9));
       
        N1.connect(new Edge(O1,2));
        O1.connect(new Edge(N1,2));
       
        O1.connect(new Edge(P1,0.75));
        O1.connect(new Edge(Q1,2.1));
        O1.connect(new Edge(R1,1.8));
        P1.connect(new Edge(O1,0.75));
        Q1.connect(new Edge(O1,2.1));
        R1.connect(new Edge(O1,1.8));
       
        Q1.connect(new Edge(R1,2.1));
        Q1.connect(new Edge(S1,4.6));
        R1.connect(new Edge(Q1,2.1));
        S1.connect(new Edge(Q1,4.6));
       
        S1.connect(new Edge(T1,0.75));
        T1.connect(new Edge(S1,0.75));
       
        T1.connect(new Edge(U1,0.3));
        T1.connect(new Edge(V1,0.5));
        U1.connect(new Edge(T1,0.3));
        V1.connect(new Edge(T1,0.5));
       
        V1.connect(new Edge(W1,0.45));
        W1.connect(new Edge(V1,0.45));
       
        W1.connect(new Edge(X1,0.85));
        X1.connect(new Edge(W1,0.85));
       
        X1.connect(new Edge(Y1,1.6));
        X1.connect(new Edge(Z1,8.6));
        Y1.connect(new Edge(X1,1.6));
        Z1.connect(new Edge(X1,8.6));
       
        Y1.connect(new Edge(Z1,8));
        Z1.connect(new Edge(Y1,8));
       
        Z1.connect(new Edge(A2,7.8));
        A1.connect(new Edge(Z1,7.8));
       
        A2.connect(new Edge(B2,9.4));
        B2.connect(new Edge(A2,9.4));
       
        B2.connect(new Edge(C2,4.9));
        C2.connect(new Edge(B2,4.9));
       
        C2.connect(new Edge(D2,0.3));
        D2.connect(new Edge(C2,0.3));
       
        D2.connect(new Edge(E2,4.6));
        D2.connect(new Edge(G2,0.6));
        E2.connect(new Edge(D2,4.6));
        G2.connect(new Edge(D2,0.6));
       
        E2.connect(new Edge(F2,7.1));
        F2.connect(new Edge(E2,7.1));
       
        G2.connect(new Edge(H2,1.1));
        G2.connect(new Edge(K2,2.4));
        H2.connect(new Edge(G2,1.1));
        K2.connect(new Edge(G2,2.4));
       
        H2.connect(new Edge(I2,1.8));
        H2.connect(new Edge(J2,1));
        I2.connect(new Edge(H2,1.8));
        J2.connect(new Edge(H2,1));
       
       
       
        //=======================================================
       
              Node n1=A;
           if(kodenode1A.equals("Wates")){n1=A;}
           else if(kodenode1A.equals("Jl. Nasional 1")){n1=B;}
           else if(kodenode1A.equals("Jl. Nasional 2")){n1=C;}
           else if(kodenode1A.equals("Jl. Nasional 3")){n1=D;}
           else if(kodenode1A.equals("Margesari")){n1=E;}
           else if(kodenode1A.equals("Jl. Diponegoro")){n1=F;}
           else if(kodenode1A.equals("Jl. Dr. Wahidin")){n1=G;}
           else if(kodenode1A.equals("Jl. KS Tubun")){n1=H;}
           else if(kodenode1A.equals("Jl. KS Tubun2")){n1=I;}
           else if(kodenode1A.equals("Jl. KS Tubun3")){n1=J;}
           else if(kodenode1A.equals("Jl. Diponegoro2")){n1=K;}
           else if(kodenode1A.equals("Jl. Airlangga")){n1=L;}
           else if(kodenode1A.equals("Jl. Yos Sudarso")){n1=M;}
           else if(kodenode1A.equals("Jl. Yos Sudarso2")){n1=N;}
           else if(kodenode1A.equals("Jl. MH Tamrin")){n1=O;}
           else if(kodenode1A.equals("Jl. Dr. Wahidin2")){n1=P;}
           else if(kodenode1A.equals("Jl. Diponegoro3")){n1=Q;}
           else if(kodenode1A.equals("Jl. Diponegoro4")){n1=R;}
           else if(kodenode1A.equals("Jl. RA Kartini")){n1=S;}
           else if(kodenode1A.equals("Jl. RA Kartin2")){n1=T;}
           else if(kodenode1A.equals("Jl. Pemuda")){n1=U;}
           else if(kodenode1A.equals("Jl. Slamet Riyadi")){n1=V;}
           else if(kodenode1A.equals("Jl. Slamet Riyadi2")){n1=W;}
           else if(kodenode1A.equals("Jl. Lingkar")){n1=X;}
           else if(kodenode1A.equals("Jl. Landoh")){n1=Y;}
           else if(kodenode1A.equals("Jl. Landoh2")){n1=Z;}
           else if(kodenode1A.equals("Seren")){n1=A1;}
           else if(kodenode1A.equals("Jl. Blora")){n1=B1;}
           else if(kodenode1A.equals("Panohan")){n1=C1;}
           else if(kodenode1A.equals("Jl. Blora2")){n1=D1;}
           else if(kodenode1A.equals("Jl. Blora3")){n1=E1;}
           else if(kodenode1A.equals("Jl. Blora4")){n1=F1;}
           else if(kodenode1A.equals("Pasucen")){n1=G1;}
           else if(kodenode1A.equals("Kutoharjo")){n1=H1;}
           else if(kodenode1A.equals("Kutoharjo2")){n1=I1;}
           else if(kodenode1A.equals("Kutoharjo3")){n1=J1;}
           else if(kodenode1A.equals("Kabongan")){n1=K1;}
           else if(kodenode1A.equals("Pasarbanggi")){n1=L1;}
           else if(kodenode1A.equals("Tritunggal")){n1=M1;}
           else if(kodenode1A.equals("Tritunggal2")){n1=N1;}
           else if(kodenode1A.equals("Punjulharjo")){n1=O1;}
           else if(kodenode1A.equals("Punjulharjo2")){n1=P1;}
           else if(kodenode1A.equals("Karangpelem")){n1=Q1;}
           else if(kodenode1A.equals("Karangpelem2")){n1=R1;}
           else if(kodenode1A.equals("Gedongmulyo")){n1=S1;}
           else if(kodenode1A.equals("Karangturi")){n1=T1;}
           else if(kodenode1A.equals("Karangturi2")){n1=U1;}
           else if(kodenode1A.equals("Karangturi3")){n1=V1;}
           else if(kodenode1A.equals("Jl. Provinsi")){n1=W1;}
           else if(kodenode1A.equals("Jl. Provinsi2")){n1=X1;}
           else if(kodenode1A.equals("Jl. Japerejo")){n1=Y1;}
           else if(kodenode1A.equals("Jl. Gunem")){n1=Z1;}
           else if(kodenode1A.equals("Jl. Pamotan")){n1=A2;}
           else if(kodenode1A.equals("Sale")){n1=B2;}
           else if(kodenode1A.equals("Sale2")){n1=C2;}
           else if(kodenode1A.equals("Jl. Kragan")){n1=D2;}
           else if(kodenode1A.equals("Bonang")){n1=E2;}
           else if(kodenode1A.equals("Jatisari")){n1=F2;}
           else if(kodenode1A.equals("Jl. Baidhowi")){n1=G2;}
           else if(kodenode1A.equals("Jl. Baidhowi2")){n1=H2;}
           else if(kodenode1A.equals("Kajar")){n1=H2;}
           else if(kodenode1A.equals("Selopuro")){n1=J2;}
           else if(kodenode1A.equals("Vihara")){n1=K2;}
         
         
            Node n2=B;
           if(kodenode1B.equals("Wates")){n2=A;}
           else if(kodenode1B.equals("Jl. Nasional 1")){n2=B;}
           else if(kodenode1B.equals("Jl. Nasional 2")){n2=C;}
           else if(kodenode1B.equals("Jl. Nasional 3")){n2=D;}
           else if(kodenode1B.equals("Margesari")){n2=E;}
           else if(kodenode1B.equals("Jl. Diponegoro")){n2=F;}
           else if(kodenode1B.equals("Jl. Dr. Wahidin")){n2=G;}
           else if(kodenode1B.equals("Jl. KS Tubun")){n2=H;}
           else if(kodenode1B.equals("Jl. KS Tubun2")){n2=I;}
           else if(kodenode1B.equals("Jl. KS Tubun3")){n2=J;}
           else if(kodenode1B.equals("Jl. Diponegoro2")){n2=K;}
           else if(kodenode1B.equals("Jl. Airlangga")){n2=L;}
           else if(kodenode1B.equals("Jl. Yos Sudarso")){n2=M;}
           else if(kodenode1B.equals("Jl. Yos Sudarso2")){n2=N;}
           else if(kodenode1B.equals("Jl. MH Tamrin")){n2=O;}
           else if(kodenode1B.equals("Jl. Dr. Wahidin2")){n2=P;}
           else if(kodenode1B.equals("Jl. Diponegoro3")){n2=Q;}
           else if(kodenode1B.equals("Jl. Diponegoro4")){n2=R;}
           else if(kodenode1B.equals("Jl. RA Kartini")){n2=S;}
           else if(kodenode1B.equals("Jl. RA Kartin2")){n2=T;}
           else if(kodenode1B.equals("Jl. Pemuda")){n2=U;}
           else if(kodenode1B.equals("Jl. Slamet Riyadi")){n2=V;}
           else if(kodenode1B.equals("Jl. Slamet Riyadi2")){n2=W;}
           else if(kodenode1B.equals("Jl. Lingkar")){n2=X;}
           else if(kodenode1B.equals("Jl. Landoh")){n2=Y;}
           else if(kodenode1B.equals("Jl. Landoh2")){n2=Z;}
           else if(kodenode1B.equals("Seren")){n2=A1;}
           else if(kodenode1B.equals("Jl. Blora")){n2=B1;}
           else if(kodenode1B.equals("Panohan")){n2=C1;}
           else if(kodenode1B.equals("Jl. Blora2")){n2=D1;}
           else if(kodenode1B.equals("Jl. Blora3")){n2=E1;}
           else if(kodenode1B.equals("Jl. Blora4")){n2=F1;}
           else if(kodenode1B.equals("Pasucen")){n2=G1;}
           else if(kodenode1B.equals("Kutoharjo")){n2=H1;}
           else if(kodenode1B.equals("Kutoharjo2")){n2=I1;}
           else if(kodenode1B.equals("Kutoharjo3")){n2=J1;}
           else if(kodenode1B.equals("Kabongan")){n2=K1;}
           else if(kodenode1B.equals("Pasarbanggi")){n2=L1;}
           else if(kodenode1B.equals("Tritunggal")){n2=M1;}
           else if(kodenode1B.equals("Tritunggal2")){n2=N1;}
           else if(kodenode1B.equals("Punjulharjo")){n2=O1;}
           else if(kodenode1B.equals("Punjulharjo2")){n2=P1;}
           else if(kodenode1B.equals("Karangpelem")){n2=Q1;}
           else if(kodenode1B.equals("Karangpelem2")){n2=R1;}
           else if(kodenode1B.equals("Gedongmulyo")){n2=S1;}
           else if(kodenode1B.equals("Karangturi")){n2=T1;}
           else if(kodenode1B.equals("Karangturi2")){n2=U1;}
           else if(kodenode1B.equals("Karangturi3")){n2=V1;}
           else if(kodenode1B.equals("Jl. Provinsi")){n2=W1;}
           else if(kodenode1B.equals("Jl. Provinsi2")){n2=X1;}
           else if(kodenode1B.equals("Jl. Japerejo")){n2=Y1;}
           else if(kodenode1B.equals("Jl. Gunem")){n2=Z1;}
           else if(kodenode1B.equals("Jl. Pamotan")){n2=A2;}
           else if(kodenode1B.equals("Sale")){n2=B2;}
           else if(kodenode1B.equals("Sale2")){n2=C2;}
           else if(kodenode1B.equals("Jl. Kragan")){n2=D2;}
           else if(kodenode1B.equals("Bonang")){n2=E2;}
           else if(kodenode1B.equals("Jatisari")){n2=F2;}
           else if(kodenode1B.equals("Jl. Baidhowi")){n2=G2;}
           else if(kodenode1B.equals("Jl. Baidhowi2")){n2=H2;}
           else if(kodenode1B.equals("Kajar")){n2=I2;}
           else if(kodenode1B.equals("Selopuro")){n2=J2;}
           else if(kodenode1B.equals("Vihara")){n2=K2;}
         
         
           //=================================================
        SearchApp mybind = new getApp();
        //String gab=mybind.getApp(n1, n2);//mybind.getApp(A, L);
        String gab=mybind.getApp(A, L);//mybind.getApp(A, L);
        double total=mybind.getCosttotal();
        String sjaraknya="+- "+String.valueOf(total)+" KM";
 
String[]ar=gab.split("#");
int p=ar.length;
String mrute="https://www.google.co.id/maps/dir/"+myLati+","+myLongi;
for(int i=0;i<p;i++){
    String kota=ar[i];
    for(int ii=0;ii<jd;ii++){
            if(kota.equalsIgnoreCase(arNama[ii])){
                mrute+="/"+String.valueOf(arLati[ii])+","+String.valueOf(arLongi[ii]);
            }
        }
}//i


gab=myPosisi+" -> "+ gab.replaceAll("#", " -> ")+myPosisi2;
cetak("MRUTE:"+gab);
cetak("MRUTE:"+mrute);
  cetak("MRUTE:"+String.valueOf(total)+" KM");
 
 
  txt1.setText(gab);
  txt2.setText(sjaraknya);
  txt3.setText(mrute);
 



 }
   

 void cetak(String info){
Log.d("Info",info);
 }
void init(){
   
    jd=70;
    arKode = new String[jd];
    arNama = new String[jd];
   
    arLati = new double[jd];
    arLongi = new double[jd];
    arJarak = new double[jd];

arKode[1]="A";
arNama[1]="Wates"; //Pantai Wates
arLati[1]=-6.690439;
arLongi[1]=111.282741;

arKode[2]="B";
arNama[2]="Jl. Nasional 1";
arLati[2]=-6.694965;
arLongi[2]=111.282782;

arKode[3]="C";
arNama[3]="Jl. Nasional 2";//Hotel pantura&hotel kartini
arLati[3]=-6.699873;
arLongi[3]=111.312078;

arKode[4]="D";
arNama[4]="Jl. Nasional 3";//hotel spbu gajah mada
arLati[4]=-6.700048;
arLongi[4]=111.313894;

arKode[5]="E";
arNama[5]="Magersari";//RM Bu Joyo
arLati[5]=-6.700715;
arLongi[5]=111.324093;

arKode[6]="F";
arNama[6]="Jl. Diponegoro";
arLati[6]=-6.704120;
arLongi[6]=111.332566;

arKode[7]="G";
arNama[7]="Jl. Dr. Wahidin";
arLati[7]=-6.705046;
arLongi[7]=111.335064;

arKode[8]="H";
arNama[8]="Jl. KS Tubun";//Sate serepeh, Sayur Mangut
arLati[8]=-6.706513;
arLongi[8]=111.334286;

arKode[9]="I";
arNama[9]="Jl. KS Tubun2";
arLati[9]=-6.708302;
arLongi[9]=111.333495;

arKode[10]="J";
arNama[10]="Jl. KS Tubun3";//De Kampoeng
arLati[10]=-6.714509;
arLongi[10]=111.333520;

arKode[11]="K";
arNama[11]="Jl. Diponegoro2";//dewa Burung
arLati[11]=-6.704043;
arLongi[11]=111.337096;

arKode[12]="L";
arNama[12]="JL. Airlangga";//Hotel antika & RM Hien
arLati[12]=-6.706450;
arLongi[12]=111.336425;

arKode[13]="M";
arNama[13]="Jl. Yos Sudarso";
arLati[13]=-708508;
arLongi[13]=111.338253;

arKode[14]="N";
arNama[14]="Jl. Yos Sudarso2";
arLati[14]=-6.709575;
arLongi[14]=111.337968;

arKode[15]="O";
arNama[15]="Jl. MH Tamrin";
arLati[15]=-6.707244;
arLongi[15]=111.338596;

arKode[16]="P";
arNama[16]="Jl. Dr. Wahidin2";
arLati[16]=-6.705447;
arLongi[16]=111.336721;

arKode[17]="Q";
arNama[17]="Jl. Diponegoro3";
arLati[17]=-6.704114;
arLongi[17]=111.339238;

arKode[18]="R";
arNama[18]="Jl. Diponegoro4";//Pantai Dampo awang, Hotel Kencana
arLati[18]=-6.704311;
arLongi[18]=111.341970;

arKode[19]="S";
arNama[19]="Jl. RA Kartini";//Hotel Sumber agung
arLati[19]=-6.706690;
arLongi[19]=111.341678;

arKode[20]="T";
arNama[20]="Jl. RA Kartini2";
arLati[20]=-6.709280;
arLongi[20]=111.341222;

arKode[21]="U";
arNama[21]="Jl. Pemuda";//Dokar, Angkutan Umum
arLati[21]=-6.710267;
arLongi[21]=111.341498;

arKode[22]="V";
arNama[22]="Jl. Slamet Riyadi";
arLati[22]=-6.712732;
arLongi[22]=111.340963;

arKode[23]="W";
arNama[23]="Jl. Slamet Riyadi2";
arLati[23]=-6.731945;
arLongi[23]=111.344583;

arKode[24]="X";
arNama[24]="Jl. Lingkar";//Kelo Mrico, Hotel Puri Indah
arLati[24]=-6.732869;
arLongi[24]=111.353741;

arKode[25]="Y";
arNama[25]="Jl. Landoh";
arLati[25]=-6.772813;
arLongi[25]=111.366723;

arKode[26]="Z";
arNama[26]="Jl. Landoh2";
arLati[26]=-6.754856;
arLongi[26]=111.332349;

arKode[27]="A1";
arNama[27]="Seren";//Karangsari Park
arLati[27]=-6.781280;
arLongi[27]=111.329724;

arKode[28]="B1";
arNama[28]="Jl. Blora";
arLati[28]=-6.859778;
arLongi[28]=111.407221;

arKode[29]="C1";
arNama[29]="Panohan";//Waduk Panohan
arLati[29]=-6.820164;
arLongi[29]=111.433418;

arKode[30]="D1";
arNama[30]="Jl. Blora2";
arLati[30]=-6.859778;
arLongi[30]=111.407221;

arKode[31]="E1";
arNama[31]="Jl. Blora3";
arLati[31]=-6.862718;
arLongi[31]=111.429381;

arKode[32]="F1";
arNama[32]="Jl. Blora4";
arLati[32]=-6.869155;
arLongi[32]=111.433124;

arKode[33]="G1";
arNama[33]="Pasucen";//Air Terjun Pasucen
arLati[33]=-6.854362;
arLongi[33]=111.482053;

arKode[34]="H1";
arNama[34]="Kutoharjo";//Terminal & Fave Hotel
arLati[34]=-6.704975;
arLongi[34]=111.348207;

arKode[35]="I1";
arNama[35]="Kutoharjo2";
arLati[35]=-6.705105;
arLongi[35]=111.350210;

arKode[36]="J1";
arNama[36]="Kutoharjo3";//Hotel Rantina&Museum RA Kartini
arLati[36]=-6.705997;
arLongi[36]=111.350212;

arKode[37]="K1";
arNama[37]="Kabongan";
arLati[37]=-6.705891;
arLongi[37]=111.359987;

arKode[39]="L1";
arNama[39]="Pasarbanggi";//Hutan Mangrove
arLati[39]=-6.703869;
arLongi[39]=111.387430;

arKode[40]="M1";
arNama[40]="Tritunggal";//Pantai Nyamplung
arLati[40]=-6.699548;
arLongi[40]=111.399279;

arKode[41]="N1";
arNama[41]="Tritunggal2";
arLati[41]=-6.692636;
arLongi[41]=111.398583;

arKode[42]="O1";
arNama[42]="Punjulharjo";//Karangjahe
arLati[42]=-6.692892;
arLongi[42]=111.415755;

arKode[43]="P1";
arNama[43]="Punjulharjo2";
arLati[43]=-6.687502;
arLongi[43]=111.412037;

arKode[44]="Q1";
arNama[44]="Karangpelem";//Caruban
arLati[44]=-6.691681;
arLongi[44]=111.433867;

arKode[45]="R1";
arNama[45]="Karangpelem2";
arLati[45]=-6.677958;
arLongi[45]=111.429700;

arKode[46]="S1";
arNama[46]="Gedongmulyo";//Hotel Surya
arLati[46]=-6.693650;
arLongi[46]=111.437478;

arKode[47]="T1";
arNama[47]="Karangturi";
arLati[47]=-6.696878;
arLongi[47]=111.443270;

arKode[48]="U1";
arNama[48]="Karangturi2";//Klenteng Cu An kiong
arLati[48]=-6.694234;
arLongi[48]=111.443622;

arKode[49]="V1";
arNama[49]="Karangturi3";
arLati[49]=-6.697798;
arLongi[49]=111.447777;

arKode[50]="W1";
arNama[50]="Jl. Provinsi";
arLati[50]=-6.701752;
arLongi[50]=111.446991;

arKode[51]="X1";
arNama[51]="Jl. Provinsi2";//Po. Madu Kismo & RM Pondok Hijau
arLati[51]=-6.708644;
arLongi[51]=111.448825;

arKode[52]="Y1";
arNama[52]="Jl. Japerejo";//Kuliner Tuyuhan
arLati[52]=-6.723273;
arLongi[52]=111.448201;

arKode[53]="Z1";
arNama[53]="Jl. Gunem";
arLati[53]=-6.765561;
arLongi[53]=111.489853;

arKode[54]="A2";
arNama[54]="Jl. Pamotan";
arLati[54]=-6.779295;
arLongi[54]=111.555938;

arKode[55]="B2";
arNama[55]="Sale";
arLati[55]=-6.850729;
arLongi[55]=111.580354;

arKode[56]="C2";
arNama[56]="Sale2";//wana wisata sumber semen
arLati[56]=-6.877441;
arLongi[56]=111.553843;

arKode[57]="D2";
arNama[57]="Jl. Kragan";
arLati[57]=-6.697848;
arLongi[57]=111.450681;

arKode[58]="E2";
arNama[58]="Bonang";//Petilasan sunan bonang
arLati[58]=-6.660531;
arLongi[58]=111.467079;

arKode[59]="F2";
arNama[59]="Jatisari";//pantai jatisari
arLati[59]=-6.633136;
arLongi[59]=111.514556;

arKode[60]="G2";
arNama[60]="Jl. Baidhowi";//makam RA Kartini
arLati[60]=-6.698207;
arLongi[60]=111.455833;

arKode[61]="H2";
arNama[61]="Jl. Baidhowi2";
arLati[61]=-6.694235;
arLongi[61]=111.465436;

arKode[62]="I2";
arNama[62]="Kajar";//Gunung Kajar
arLati[62]=-6.688457;
arLongi[62]=111.479835;

arKode[63]="J2";
arNama[63]="Selopuro";//Watu congol
arLati[63]=-6.697746;
arLongi[63]=111.471489;

arKode[64]="K2";
arNama[64]="Vihara";//vihara ratanavana
arLati[64]=-6.705893;
arLongi[64]=111.472934;

     
       

       
}


 public static double getJarak(double lat1, double lng1, double lat2, double lng2) {
           double earthRadius = 3958.75;
           double dLat = Math.toRadians(lat2-lat1);
           double dLng = Math.toRadians(lng2-lng1);
           double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                      Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
                      Math.sin(dLng/2) * Math.sin(dLng/2);
           double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
           double dist = earthRadius * c;

           int meterConversion = 1609;
           double myjr=dist * meterConversion;
           return Math.floor(myjr/1000);

}
}


++++++++++++++++++++++++++


import java.util.ArrayList;


public class SearhApp{
    private double costtotal;
    
    String getApp(Node start, Node goal){
       String gab="";
        ArrayList<Node> closed = new ArrayList<Node>();
        ArrayList<Node> open = new ArrayList<Node>();
        open.add(start);
        start.setFn(start.getGn()+start.getHn());
       
        System.out.print("        OPEN : ");
        System.out.println(open);
        
         
        while(open.isEmpty() == false){        
            Node best;
            if (open.contains(goal)){
                int position = open.indexOf(goal);
                best = open.get(position);
            } else {
                //selection sort
                for (int i=0; i< open.size()-1; i++ ){
                    int min=i;
                    for(int j = i+1; j<open.size(); j++) {
                        if(open.get(j).getFn() < open.get(min).getFn()) {
                            min=j;
                        }
                      }
                        Node temp = open.get(min);
                        open.set(min, open.get(i));
                        open.set(i, temp);
                } 
                best = open.get(0);    
            }
            
            if (open.contains(best)){
                open.remove(best);
            }

            
            System.out.print("        CLOSED : ");
            System.out.println(closed);
            closed.add(best);
            System.out.println("   ***BEST NODE : "+best.getNama()+"***");
            System.out.print("        OPEN : ");
            System.out.println(open);
            System.out.print("        CLOSED : ");
            System.out.println(closed);
            System.out.println();
            System.out.println();
            
            if(best.getNama() == goal.getNama()){
                gab="";
               // costtotal=0;
                for(int i=0;i<closed.size();i++){
                     String kota=closed.get(i).toString();
                     //System.out.println("Kota:"+kota);
                     double jarak=closed.get(i).getGn();
                     costtotal=jarak;
                     gab+=kota+"#";
                }
                return gab;
            }
                      
                    
            for(Edge e:best.getChildlist()){
                Node child = e.getTargetnode();
                double tempcost = e.getCost();
                double tempGn = best.getGn()+ tempcost;
                double tempFn = tempGn + child.getHn();              
                
                if (closed.contains(child)){
                    continue;
                }  else if (!open.contains(child)) {
                    child.setFn(tempFn);
                    child.setGn(tempGn);
                    child.setParentnode(best);
                    if (open.contains(child)) {
                        open.remove(child);
                    }
                    open.add(child); 
                }
            }
            System.out.print("        OPEN : ");
            System.out.println(open);          
        }
        return " ";
    }
    
    public void printRute(Node goal){
        ArrayList<Node> rute = new ArrayList<Node>();

        for (Node n = goal; n != null; n = n.getParentnode()){
            rute.add(n);
        }
      //  costtotal=costtotal+goal.getGn(); 

        for (int i=rute.size()-1; i>=0; i--){
            System.out.print(rute.get(i).getNama()+" ");
        }
    }

    public double getCosttotal() {
        return costtotal;
    }

    public void setCosttotal(double costtotal) {
        this.costtotal = costtotal;
    }
}

+++++++++++++++++++++Node.java

import java.util.ArrayList;
import java.util.List;


public class Node {
    private String nama;
    private double gn;
    private double fn;
    private double hn;
    private List<Edge> childlist;
    private Node parentnode;

   
    @Override
    public String toString(){
        return this.nama;//+"("+this.fn+")";
    }
     
    public Node(String nama, double hn){
        this.nama=nama;
        this.hn=hn;
        this.childlist=new ArrayList<Edge>();
    }
    
    public void connect(Edge e){
        this.getChildlist().add(e);
    }

    public String getNama() {
        return nama;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public double getGn() {
        return gn;
    }

    public void setGn(double gn) {
        this.gn = gn;
    }

    public double getFn() {
        return fn;
    }

    public void setFn(double fn) {
        this.fn = fn;
    }

    public double getHn() {
        return hn;
    }

    public void setHn(double hn) {
        this.hn = hn;
    }

    public List<Edge> getChildlist() {
        return childlist;
    }

    public void setChildlist(List<Edge> childlist) {
        this.childlist = childlist;
    }

    public Node getParentnode() {
        return parentnode;
    }

    public void setParentnode(Node parentnode) {
        this.parentnode = parentnode;
    }
    
 
}

++++++++++++++++++++++++++++++++Edge.java

 
public class Edge {
    private double cost;
    private Node targetnode;
    
    public Edge(Node target, double cost) {
        targetnode=target;
        this.cost=cost;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public Node getTargetnode() {
        return targetnode;
    }

    public void setTargetnode(Node targetnode) {
        this.targetnode = targetnode;
    }
    
    
}

Tidak ada komentar:

Posting Komentar