menuutama.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/kayu_bintagor"
android:orientation="vertical" >
<TextView
android:id="@+id/menuMarquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="50dp"
android:background="#000000"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="selamat datang di aplikasi android "
android:textColor="#0000ff"
android:textSize="16sp"
android:typeface="sans" />
<ImageView
android:id="@+id/imgPosisi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="42dp"
android:layout_marginTop="44dp"
android:src="@drawable/earth" />
<ImageView
android:id="@+id/imgDataSt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/imgPosisi"
android:layout_marginRight="52dp"
android:src="@drawable/home" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="26dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignRight="@+id/imgDataSt"
android:text="Lokasi"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView5"
android:layout_below="@+id/imagehelp"
android:text="Help"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView6"
android:layout_alignRight="@+id/imginput"
android:text="Profil"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/imagehelp"
android:layout_alignRight="@+id/imginput"
android:text="Input"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<ImageView
android:id="@+id/imginput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView3"
android:layout_centerVertical="true"
android:src="@drawable/add" />
<ImageView
android:id="@+id/imgCari"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_centerVertical="true"
android:src="@drawable/search" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/imgPosisi"
android:layout_below="@+id/imgPosisi"
android:text="Posisi"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/imgCari"
android:text="Search"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<ImageView
android:id="@+id/imagehelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imgCari"
android:layout_below="@+id/textView5"
android:src="@drawable/help" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/imgDataSt"
android:layout_centerHorizontal="true"
android:text="MENU UTAMA"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<ImageView
android:id="@+id/imgprofil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView7"
android:layout_alignRight="@+id/textView7"
android:src="@drawable/user_woman" />
</RelativeLayout>
menuutama.java
package com.lp2maray.jakarta;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.text.Html;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class menuutama extends Activity {
String
myLati="-6.353516";
String
myLongi="106.832307";
String myLokasi="LP2M ARAY Jakarta - Indonesia (default)";
LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menuutama);
ImageView Lokasi=(ImageView)findViewById(R.id.imgPosisi);
Lokasi.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i= new Intent(menuutama.this, Maps.class);
i.putExtra("myLati", myLati);
i.putExtra("myLongi", myLongi);
i.putExtra("myLokasi", myLokasi);
startActivity(i);
}});
ImageView profil=(ImageView)findViewById(R.id.imgprofil);
profil.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i= new Intent(menuutama.this, profil.class);
startActivity(i);
}});
ImageView bantuan=(ImageView)findViewById(R.id.imagehelp);
bantuan.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i= new Intent(menuutama.this, bantuan.class);
startActivity(i);
}});
ImageView input=(ImageView)findViewById(R.id.imginput);
input.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i= new Intent(menuutama.this, listdataDB.class);
i.putExtra("myLati", myLati);
i.putExtra("myLongi", myLongi);
i.putExtra("myLokasi", myLokasi);
startActivity(i);
}});
ImageView cari=(ImageView)findViewById(R.id.imgCari);
cari.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i= new Intent(menuutama.this, pencarian.class);
i.putExtra("myLati", myLati);
i.putExtra("myLongi", myLongi);
i.putExtra("myLokasi", myLokasi);
startActivity(i);
}});
ImageView list=(ImageView)findViewById(R.id.imgDataSt);
list.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {//liststasiun
Intent i= new Intent(menuutama.this, check.class);
i.putExtra("myLati", myLati);
i.putExtra("myLongi", myLongi);
i.putExtra("myLokasi", myLokasi);
startActivity(i);
}});
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(provider, 5000, 10,locationListener);
TextView txtMarquee=(TextView)findViewById(R.id.menuMarquee);
txtMarquee.setSelected(true);
String kata=".: Posisi "+myLokasi+"("+myLati+"."+myLongi+" Selamat Datang Di LP2M ARAY Jakarta - Indonesia (default)#";
String POLA =getString(R.string.marquee);
String kalimat=String.format(POLA,TextUtils.htmlEncode(kata+kata+kata));
txtMarquee.setText(Html.fromHtml(kalimat));
}
private final LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
@Override
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
@Override
public void onProviderEnabled(String provider){ }
@Override
public void onStatusChanged(String provider, int status, Bundle extras){ }
};
private void updateWithNewLocation(Location location) {
String latLongString;
double latitude=Double.parseDouble(myLati);
double longitude=Double.parseDouble(myLongi);
String addressString = "default";
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
myLati=String.valueOf(latitude);
myLongi=String.valueOf(longitude);
latLongString = "Lat:" + latitude + "\nLong:" + longitude;
Geocoder gc = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
} catch (IOException e) {}
} else {
myLati="-6.353128";
myLongi="106.832307";
latLongString="LP2M ARAY Jakarta - Indonesia (default)";
}
myLokasi=latLongString + "\n" + addressString;
myLati=String.valueOf(myLati);
myLongi=String.valueOf(myLongi);
TextView txtMarquee=(TextView)findViewById(R.id.menuMarquee);
txtMarquee.setSelected(true);
String kata=".: --Posisi "+myLokasi+"("+myLati+","+myLongi+" LP2M ARAY Jakarta - Indonesia (default)--";
String POLA =getString(R.string.marquee);
String kalimat=String.format(POLA,TextUtils.htmlEncode(kata+kata+kata));
txtMarquee.setText(Html.fromHtml(kalimat));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
+++++++++++++
Maps.java
package com.example.may16;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
public class Maps extends FragmentActivity{
private GoogleMap map;
String myLati="-6.353516";
String myLongi="106.832307";
String myLokasi="LP2M ARAY Jakarta - Indonesia (default)";
int jd=0;
String[]arr_id;
String[]arr_longitude;
String[]arr_keterangan;
String[]arr_nama;
String[]arr_alamat;
String[]arr_latitude;
int[]arrGbr;
dbHelper helper=null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
Intent io = this.getIntent();
myLokasi=io.getStringExtra("myLokasi");
myLati=io.getStringExtra("myLati");
myLongi=io.getStringExtra("myLongi");
helper=new dbHelper(this);
Cursor c=helper.getAll();
c.moveToFirst();
int row = c.getCount();
jd=row;
int i=0;
if (row>0){
arr_nama=new String[jd];
arr_alamat=new String[jd];
arr_latitude=new String[jd];
arr_id=new String[jd];
arr_longitude=new String[jd];
arr_keterangan=new String[jd];
arrGbr=new int[jd];
for(i=0;i<row;i++){
arr_id[i]=helper.getid(c);
arr_nama[i]=helper.getnama(c);
arr_alamat[i]=helper.getalamat(c);
arr_latitude[i]=helper.getlatitude(c);
arr_longitude[i]=helper.getlongitude(c);
arr_keterangan[i]=helper.getketerangan(c);
arrGbr[i]=R.drawable.add;
try{c.moveToNext();}
catch(Exception ee){}
}
c.close();
setupMap();
}
else{
Toast.makeText(Maps.this," Maaf data belum tersedia....", Toast.LENGTH_LONG).show();
finish();
}
}
private void setupMap(){
if (map == null){
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maps)).getMap();
if (map != null){
double mlati=Double.parseDouble(myLati);
double mlongi=Double.parseDouble(myLongi);
map.addMarker(new MarkerOptions().position(new LatLng(mlati,mlongi)).title("Posisi Anda").snippet(myLokasi).icon(BitmapDescriptorFactory.fromResource(drawableId));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mlati, mlongi),10));
for(int i=0;i<jd;i++){
try {
mlati=Double.parseDouble(arr_latitude[i]);
mlongi=Double.parseDouble(arr_longitude[i]);
} catch (NumberFormatException e) {
mlati=Double.parseDouble(myLati);
mlongi=Double.parseDouble(myLongi);
e.printStackTrace();
}
map.addMarker(new MarkerOptions().position(new LatLng(mlati,mlongi)).title(arr_nama[i]).snippet(arr_alamat[i]));
}
}
}
}
}
NB:
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.pin);
LatLng latLng = new LatLng(21.4225, 39.8262);
googleMap.addMarker(new MarkerOptions().position(latLng).title("Mecca").icon(icon)).showInfoWindow();
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
<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"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<fragment
android:id="@+id/maps"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>