public class LocateMe extends Activity
{
public void onCreate(Bundle params)
{
super.onCreate(params);
setContentView(R.layout.main);
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return true;
}
}
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="Press the center key to locate yourself" /> </RelativeLayout>
public final class R
{
public static final class layout
{
public static final int main=0x7f030001;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode != KeyEvent.KEYCODE_DPAD_CENTER || m_bLoading)
{
return true;
}
m_bLoading = true;
getLocation();
return true;
}
private void getLocation()
{
Location loc;
LocationManager locMan;
LocationProvider locPro;
List<LocationProvider> proList;
setContentView(R.layout.laoding);
locMan = (LocationManager) getSystemService(LOCATION_SERVICE);
proList = locMan.getProviders();
locPro = proList.get(0);
loc = locMan.getCurrentLocation(locPro.getName());
Lat = (float)loc.getLatitude();
Lon = (float)loc.getLongitude();
CreateView();
setContentView(customView);
}
public voidCreateView(){
customView = newCustomView(this);
}
public class CustomView extendsView{
LocateMe overlord;
publicCustomView(LocateMe pCtx){
super(pCtx);
overlord = pCtx;
}
public voidonDraw(Canvas cvs){
Paint p = newPaint();
String sLat = "Latitude: "+ overlord.getLat();
String sLon = "Longitude: "+ overlord.getLon();
cvs.drawText(sLat , 32, 32, p);
cvs.drawText(sLon, 32, 44, p);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有