package test99.test;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MapView.LayoutParams;
public class MappActivity extends MapActivity {
/** Called when the activity is first created. */
MapView mapView;
MapController mapCtrl;
String locationProvider;
LocationManager locationManager;
Location location;
int latitude,longitude;
private ImageButton button1;
private ImageButton button2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
mapView=(MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
GeoPoint gPoint=new GeoPoint((int)(37.566912*1E6),126978517);
mapCtrl=mapView.getController();
mapCtrl.setCenter(gPoint);
mapCtrl.setZoom(17);
locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationProvider=locationManager.getBestProvider(new Criteria(),true);
Location location=locationManager.getLastKnownLocation(locationProvider);
if(location!=null){
latitude=(int)(location.getLatitude()*1000000);
longitude=(int)(location.getLongitude()*1000000);
}
startLocationService();
GeoPoint pt1=new GeoPoint(latitude,longitude);
mapCtrl.setCenter(pt1);
ImageButton imagebtn=new ImageButton(this);
imagebtn.setBackgroundResource(R.drawable.flag);
imagebtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "현재위치입니다.", Toast.LENGTH_LONG).show();
}
});
MapView.LayoutParams lp1=new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, pt1, MapView.LayoutParams.CENTER);
mapView.addView(imagebtn, lp1);
GeoPoint pt2=new GeoPoint(37225335,127188275);
ImageButton imagebtn2=new ImageButton(this);
imagebtn2.setBackgroundResource(R.drawable.oneroom);
imagebtn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog dialogBox=createDialogBox("명지원룸","tel:031-666-1111");
dialogBox.show();
}
});
MapView.LayoutParams lp2=new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, pt2, MapView.LayoutParams.CENTER);
mapView.addView(imagebtn2, lp2);
GeoPoint pt3=new GeoPoint(37226031,127191188);
ImageButton imageBtn3=new ImageButton(this);
imageBtn3.setBackgroundResource(R.drawable.oneroom);
imageBtn3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog dialogBox=createDialogBox("동진원룸","tel:031-666-3333");
dialogBox.show();
}
});
MapView.LayoutParams lp3=new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, pt3, MapView.LayoutParams.CENTER);
mapView.addView(imageBtn3, lp3);
GeoPoint pt4=new GeoPoint(37225164,127184660);
ImageButton imageBtn4=new ImageButton(this);
imageBtn4.setBackgroundResource(R.drawable.oneroom);
imageBtn4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog dialogBox=createDialogBox("덕곡원룸","tel:031-555-4444");
dialogBox.show();
}
});
MapView.LayoutParams lp4=new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, pt4, MapView.LayoutParams.CENTER);
mapView.addView(imageBtn4, lp4);
GeoPoint pt5=new GeoPoint(37230580,127188887);
ImageButton imageBtn5=new ImageButton(this);
imageBtn5.setBackgroundResource(R.drawable.oneroom);
imageBtn5.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog dialogBox=createDialogBox("이마트원룸","tel:031-444-5555");
dialogBox.show();
}
});
MapView.LayoutParams lp5=new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, pt5, MapView.LayoutParams.CENTER);
mapView.addView(imageBtn5, lp5);
GeoPoint pt6=new GeoPoint(37226271,127188292);
ImageButton imageBtn6=new ImageButton(this);
imageBtn6.setBackgroundResource(R.drawable.oneroom);
imageBtn6.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog dialogBox=createDialogBox("스타빌","tel:031-123-4567");
dialogBox.show();
}
});
MapView.LayoutParams lp6=new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, pt6, MapView.LayoutParams.CENTER);
mapView.addView(imageBtn6, lp6);
GeoPoint pt7=new GeoPoint(37225459,127187497);
ImageButton imageBtn7=new ImageButton(this);
imageBtn7.setBackgroundResource(R.drawable.chiken);
imageBtn7.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog dialogBox=createChikenDialogBox("치땡","tel:031-444-5212");
dialogBox.show();
}
});
MapView.LayoutParams lp7=new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, pt7, MapView.LayoutParams.CENTER);
mapView.addView(imageBtn7, lp7);
GeoPoint pt8=new GeoPoint(37231327,127188693);
ImageButton imageBtn8=new ImageButton(this);
imageBtn8.setBackgroundResource(R.drawable.pizza);
imageBtn8.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog dialogBox=createPizzaDialogBox("이마트피자","tel:031-412-4252");
dialogBox.show();
}
});
MapView.LayoutParams lp8=new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, pt8, MapView.LayoutParams.CENTER);
mapView.addView(imageBtn8, lp8);
}
private AlertDialog createDialogBox(String name,final String phoneNumber){
AlertDialog myDialog = new AlertDialog.Builder(this)
//set message, title, and icon
.setTitle(name)
.setMessage(phoneNumber)
.setIcon(R.drawable.jip)
.setPositiveButton("전화걸기",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Uri number=Uri.parse(phoneNumber);
Intent dial=new Intent(Intent.ACTION_DIAL,number);
startActivity(dial);
};
})
.setNegativeButton("취소",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create();
return myDialog;
}
private AlertDialog createChikenDialogBox(String name,final String phoneNumber){
AlertDialog myDialog = new AlertDialog.Builder(this)
//set message, title, and icon
.setTitle(name)
.setMessage(phoneNumber)
.setIcon(R.drawable.bbq)
.setPositiveButton("전화걸기",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Uri number=Uri.parse(phoneNumber);
Intent dial=new Intent(Intent.ACTION_DIAL,number);
startActivity(dial);
};
})
.setNegativeButton("취소",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create();
return myDialog;
}
private AlertDialog createPizzaDialogBox(String name,final String phoneNumber){
AlertDialog myDialog = new AlertDialog.Builder(this)
//set message, title, and icon
.setTitle(name)
.setMessage(phoneNumber)
.setIcon(R.drawable.pizzahut)
.setPositiveButton("전화걸기",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Uri number=Uri.parse(phoneNumber);
Intent dial=new Intent(Intent.ACTION_DIAL,number);
startActivity(dial);
};
})
.setNegativeButton("취소",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create();
return myDialog;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
private void startLocationService() {
// get manager instance
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// set listener
GPSListener gpsListener = new GPSListener();
long minTime = 10000;
float minDistance = 0;
manager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
minTime,
minDistance,
gpsListener);
Toast.makeText(getApplicationContext(), "지도정보를 가져오는 중입니다.", Toast.LENGTH_SHORT).show();
}
private class GPSListener implements LocationListener {
public void onLocationChanged(Location location) {
//capture location data sent by current provider
Double latitude = location.getLatitude();
Double longitude = location.getLongitude();
}
public void onProviderDisabled(String provider) {
Toast.makeText(getApplicationContext(), "지도정보를 가져오는데 성공했습니다.", Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider) {
Toast.makeText(getApplicationContext(), "지도정보를 가져오는데 실패했습니다.", Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
}
아참 포팅 기기는 갤2입니다. 4.03 기반으로 만들었구요