Advertisement
rachmadi

MainActivity Maps Trigger

Jun 12th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package info.rekayasa.mapstrigger;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12.     double latitude, longitude;
  13.     Button btnPeta;
  14.  
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_main);
  19.  
  20.         btnPeta = (Button) findViewById(R.id.btnPeta);
  21.  
  22.         btnPeta.setOnClickListener(new View.OnClickListener() {
  23.             @Override
  24.             public void onClick(View v) {
  25.                 // latitude dan longitude dari json dimasukin di variable2 ini
  26.                 latitude = -2.987538;
  27.                 longitude = 104.760214;
  28.  
  29.                 // Buat intent yg akan memuat lokasi
  30.                 Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + latitude + ", " + longitude + "(Palembang)");
  31.                 Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
  32.                 mapIntent.setPackage("com.google.android.apps.maps");
  33.                 startActivity(mapIntent);
  34.             }
  35.         });
  36.  
  37.  
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement