package com.fozhyn;
import java.util.List;
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.Overlay;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;
public class MainAppActivity extends MapActivity {
/** Called when the activity is first created. */
ImageButton btnSearch;
ImageButton btnLayer;
ImageButton btnMyLocation;
EditText edAddr;
MapView myMapView;
MapController myMapCtrler;
LinearLayout hideCusor;
Boolean flag;
Boolean updateLocation;
Bitmap posBitmap,locBitmap;
LocationManager myLocationManager;
Location myLocation;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
posBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.pos);
locBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.loc);
btnMyLocation = (ImageButton)findViewById(R.id.loction);
btnSearch = (ImageButton)findViewById(R.id.btnSearch);
edAddr = (EditText)findViewById(R.id.addr);
myMapView= (MapView)findViewById(R.id.mapView01);
btnSearch.setOnClickListener(btnSearchListener);
hideCusor =(LinearLayout)findViewById(R.id.hideCursor);
btnLayer = (ImageButton)findViewById(R.id.layer);
btnLayer.setOnClickListener(btnLayerLister);
btnMyLocation.setOnClickListener(btnMyLocationListener);
flag = true;
updateLocation = true;
myMapView.setBuiltInZoomControls(true);
myMapCtrler = myMapView.getController();
myMapCtrler.setZoom(10);
myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if (myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) == false) {
//Toast.makeText(getApplicationContext(), "请打开GPS以获取位置", Toast.LENGTH_LONG).show();
new AlertDialog.Builder(this)
.setTitle("提高我的位置精确度")
.setMessage("如需获取更精确的位置服务,请您在室外并打开GPS")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try
{
startActivity(intent);
} catch(ActivityNotFoundException ex)
{
// The Android SDK doc says that the location settings activity
// may not be found. In that case show the general settings.
// General settings activity
intent.setAction(Settings.ACTION_SETTINGS);
try {
startActivity(intent);
} catch (Exception e) {
}
}
// android.os.Process.killProcess(android.os.Process.myPid());
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
// TODO Auto-generated method stub
}
}).show();
}
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, myLocationListener);
myLocation = getLocation(myLocationManager);
btnMyLocation.performClick();
}
final static int MENU_SEARCH = Menu.FIRST;
final static int MENU_SWITCH = Menu.FIRST+1;
final static int MENU_QUIT = Menu.FIRST+2;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
menu.add(0,MENU_SEARCH,0,"搜索地图");
menu.add(0,MENU_SWITCH,1,"切换视图");
menu.add(0,MENU_QUIT,2,"退出");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case MENU_SEARCH:
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
edAddr.requestFocus();
break;
case MENU_SWITCH:
if (flag) {
myMapView.setSatellite(true);
flag = false;
Toast.makeText(getApplicationContext(), "切换到卫星地图视图", Toast.LENGTH_SHORT).show();
}
else {
myMapView.setSatellite(false);
flag = true;
Toast.makeText(getApplicationContext(), "切换到普通地图视图", Toast.LENGTH_SHORT).show();
}
break;
case MENU_QUIT:
new AlertDialog.Builder(this)
.setTitle("退出")
.setMessage("确定要退出程序?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
android.os.Process.killProcess(android.os.Process.myPid());
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
// TODO Auto-generated method stub
}
}).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
//根据经纬度更新视图
private void UpdateMapView(double lng,double lat,Bitmap bitmap)
{
GeoPoint geoPoint = new GeoPoint((int) (lat * 1E6)
, (int) (lng * 1E6));
//设置显示缩放按钮
myMapView.displayZoomControls(true);
//定位到指定位置
myMapCtrler.animateTo(geoPoint);
//获取并清除mapview上的原有overlay对象
List<Overlay> overlays = myMapView.getOverlays();
overlays.clear();
//添加新的overlay对象
overlays.add(new PosOverlay(geoPoint, bitmap));
}
//获取位置
public Location getLocation(LocationManager lm) {
Location location = null;
try {
Criteria myCriteria = new Criteria();
//设置精准度
myCriteria.setAccuracy(Criteria.ACCURACY_FINE);
myCriteria.setAltitudeRequired(false);
myCriteria.setBearingRequired(false);
myCriteria.setCostAllowed(true);
myCriteria.setPowerRequirement(Criteria.POWER_LOW);
location = lm.getLastKnownLocation(lm.getBestProvider(myCriteria, true));
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
//监听搜索按钮点击事件
private final View.OnClickListener btnSearchListener = new View.OnClickListener() {
@Override
public void onClick(View arg0) {
updateLo
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
MobileMapDemo.rar (78个子文件)
MobileMapDemo
AndroidManifest.xml 1KB
res
layout
main.xml 2KB
drawable-ldpi
ic_launcher.png 3KB
drawable-mdpi
ic_launcher.png 5KB
drawable-hdpi
layer.png 5KB
pos.gif 762B
searchn.9.png 1KB
point_start.png 5KB
bubble_backgroundn.9.png 1KB
searchf.9.png 4KB
bubble_backgroundf.9.png 1KB
loction.png 5KB
expander_ic_minimized.9.png 2KB
point_where.png 4KB
maptitlebtnn.png 4KB
bubble_background.xml 351B
maptitlebtn.xml 341B
pointwhat.png 4KB
icon.png 7KB
maptitlebtnf.png 3KB
searchbg.png 469B
searchbtn.xml 331B
loc.gif 1KB
ic_launcher.png 9KB
values
strings.xml 321B
src
com
fozhyn
Navigation.java 114B
ConvertUtil.java 3KB
PosOverlay.java 1KB
MainAppActivity.java 12KB
SearchThread.java 326B
bin
classes
com
fozhyn
MainAppActivity.class 8KB
MainAppActivity$3.class 2KB
MainAppActivity$5.class 1KB
MainAppActivity$2.class 2KB
Navigation.class 292B
MainAppActivity$1.class 2KB
MainAppActivity$7.class 934B
BuildConfig.class 329B
R.class 475B
R$layout.class 370B
R$attr.class 316B
MainAppActivity$10.class 875B
MainAppActivity$8.class 845B
ConvertUtil.class 3KB
MainAppActivity$6.class 828B
R$id.class 518B
R$string.class 496B
R$drawable.class 1KB
PosOverlay.class 1KB
SearchThread.class 515B
MainAppActivity$4.class 2KB
MainAppActivity$9.class 837B
res
drawable-ldpi
ic_launcher.png 3KB
drawable-mdpi
ic_launcher.png 5KB
drawable-hdpi
layer.png 1KB
searchn.9.png 1KB
point_start.png 3KB
bubble_backgroundn.9.png 1KB
searchf.9.png 3KB
bubble_backgroundf.9.png 1KB
loction.png 1KB
expander_ic_minimized.9.png 2KB
point_where.png 981B
maptitlebtnn.png 845B
pointwhat.png 866B
icon.png 5KB
maptitlebtnf.png 157B
searchbg.png 255B
ic_launcher.png 9KB
jarlist.cache 119B
classes.dex 17KB
MobileMapDemo.apk 62KB
resources.ap_ 50KB
.classpath 364B
assets
project.properties 578B
.project 849B
gen
com
fozhyn
R.java 2KB
BuildConfig.java 152B
共 78 条
- 1
资源评论
- anfeitaming22012-10-24资源非常好,就是有些小错误要手动修改下,很全
fozhyn
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功