导航:首页 > 操作系统 > android指南针开发

android指南针开发

发布时间:2023-06-09 22:30:37

android软件开发,指南针校准对陀螺仪有依赖吗

没有,指南针底层的校准只依赖指南针本身的报值和ACC(加速度传感器)的报值。
如果你手头有你的指南针的内核源码(包括.a文件中的函数),我可以详细说给你

编程 安卓 Android studio 传感器 指南针

如果这个LinerLayout 和 ImageView 是官方的,那么应该开头中间大写,如果是自定义的那么要写全路径。
java 代码报错是应为你的xml控件报错,没办法findviewbyid。
全部问题都是正确书写xml就好

⑶ android 手机 地图 定位 编程 如何获取 定位的地点 的图片 和 文字 信息

最近开发中使用的是网络地图android SDK:
1、初始化地图
2、注册定位监听器,初始化Location模块
3、初始化定位图层;启用定位,启用指南针,最后把定位图层添加到地图中。附简单代码:

//mMapView = (MapView) findViewById(R.id.bmapsView);
mMapView = new MapView(this); //初始化一个mapView 存放Map
mMapView.setBuiltInZoomControls(true);// 设置启用默认的缩放控件

locationManager = mBMapMan.getLocationManager();
/*
* 由于LocationListener获取第一个位置修正的时间会很长,为了避免用户等待,
* 在LocationListener获取第一个更精确的位置之前,应当使用getLocationInfo() 获取一个缓存的位置
*/
Location location = locationManager.getLocationInfo();
locationManager.requestLocationUpdates(this);

mMapController = mMapView.getController();// 得到mMapView的控制权,可以用它控制和驱动平移和缩放
if (location != null) {
mMapController.setCenter(new GeoPoint(
(int) (location.getLatitude() * 1E6), (int) (location
.getLongitude() * 1E6)));
}
mMapController.setZoom(12);// 设置地图zoom级别

MyLocationOverlay mylocTest = new MyLocationOverlay(this, mMapView);
mylocTest.enableMyLocation();
mylocTest.enableCompass();
mMapView.getOverlays().add(mylocTest);
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub

if (location != null) {
mMapController.animateTo(new GeoPoint(
(int) (location.getLatitude() * 1E6), (int) (location
.getLongitude() * 1E6)));
}
}

如果你想点击定位地点,显示信息,你需要去扩展MyLocationOverlay图层,它里面有个public boolean onTap(GeoPoint p, MapView map) {}方法,是处理点击事件的。

有问题,可以与我联系,共同探讨。

⑷ 高德地图,android开发中,怎么用经纬度来显示地图

首先创建工程,并在工程Build Path>Configure Build Path…>libraries 中选择“Add Externel JARs…”,选定

MapApi.jar,点击OK,这样就可以将高德地图Android API 库文件引入。然后在工程Build Path>Configure Build

Path…>Order and Export 中将引入的库文件MapApi.jar 选中,点击OK,这样您就可以在您的程序中使用高德地图API

了。

二、我们在不熟悉的情况下、先尽量多的添加此软件应用权限;所以在mainifest中添加如下代码;插入的位置在

<application的代码之前。

Java代码
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>

三、接着就要在res文件下的layout中添加界面布局了。其代码如下、你可以完全复制进去。

Java代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!--添加文本输入框,查找地址-->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content" android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="经度"/>
<EditText android:layout_height="fill_parent"
android:layout_width="100px"
android:id="@+id/longitude"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="纬度"/>
<EditText android:layout_height="fill_parent"
android:layout_width="100px"
android:id="@+id/latitude"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查找"
android:id="@+id/button"/>
</LinearLayout>

<com.amap.mapapi.map.MapView android:id="@+id/mapView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:clickable="true"
/>
</LinearLayout>

四、最后就是软件的主程序部分了、里面需要的类和方法不多,主要以按钮的监听器和地图的界面实现为主

Java代码
public void onCreate(Bundle savedInstanceState) {
// this.setMapMode(MAP_MODE_VECTOR);//设置地图为矢量模式

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setBuiltInZoomControls(true); // 设置启用内置的缩放控件
mMapController = mMapView.getController(); // 得到mMapView
// 的控制权,可以用它控制和驱动平移和缩放
point = new GeoPoint((int) (39.982378 * 1E6), (int) (116.304923 * 1E6)); // 用给定的经纬度构造一个GeoPoint,单位是微度(度*
// 1E6)
// 按钮添加监听器
button_location = (Button) findViewById(R.id.location);
longitude = (EditText) findViewById(R.id.longitude);
latite = (EditText) findViewById(R.id.latitude);
locationListener = new OnClickListener() {
public void onClick(View e) {
if (e.equals(button_location)) {
// 得到文本输入框的中经纬 度坐标值
String latStr = longitude.getText().toString();
// 将得到的字符串转成数值
double lat = Integer.parseInt(latStr);
String lngStr = latite.getText().toString();
double lng = Integer.parseInt(lngStr);
//转成经纬度坐标
lat=lat*1E6;
lng=lng*1E6;
// 用给定的经纬度构造一个GeoPoint,单位是微度(度*1E6)
point = new GeoPoint((int) (lat), (int) (lng));
mMapController.setCenter(point); // 设置地图中心点
mMapController.setZoom(12); // 设置地图zoom 级别
// 添加地图覆盖物
// MyLocationOverlay(this, mMapView);
mylocTest.enableMyLocation(); // 判断是否发现位置提供者
mylocTest.enableCompass(); // 打开指南针
mMapView.getOverlays().add(mylocTest);// 添加定位覆盖物
}
}
};
// 按钮添加监听器
button_location.setOnClickListener(locationListener);
mMapController.setCenter(point); // 设置地图中心点
mMapController.setZoom(12); // 设置地图zoom 级别
// 添加地图覆盖物
mylocTest = new MyLocationOverlay(this, mMapView);
mylocTest.enableMyLocation(); // 判断是否发现位置提供者
mylocTest.enableCompass(); // 打开指南针
mMapView.getOverlays().add(mylocTest);// 添加定位覆盖物
}
//另外一个添加界面覆盖物的类:

public class MyLocationOverlayProxy extends com.amap.mapapi.map.MyLocationOverlay{

private Location mLocation;
protected final Paint mPaint = new Paint();
protected final Paint mCirclePaint = new Paint();
private Bitmap gps_marker=null;
private Point mMapCoords = new Point();
private final float gps_marker_CENTER_X;
private final float gps_marker_CENTER_Y;
private final LinkedList<Runnable> mRunOnFirstFix = new LinkedList<Runnable>();
public MyLocationOverlayProxy(amap amap, MapView mMapView) {

super(amap, mMapView);
gps_marker = ((BitmapDrawable) amap.getResources().getDrawable(
R.drawable.marker_gpsvalid)).getBitmap();
gps_marker_CENTER_X = gps_marker.getWidth() / 2 - 0.5f;
gps_marker_CENTER_Y= gps_marker.getHeight() / 2 - 0.5f;
}

public boolean runOnFirstFix(final Runnable runnable) {
if (mLocation != null) {
new Thread(runnable).start();
return true;
} else {
mRunOnFirstFix.addLast(runnable);
return false;
}
}

public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
mLocation = location;
for(final Runnable runnable : mRunOnFirstFix) {
new Thread(runnable).start();
}
mRunOnFirstFix.clear();
super.onLocationChanged(location);
}

protected void drawMyLocation(Canvas canvas, MapView mapView, final Location mLocation,
GeoPoint point, long time) {
Projection pj=mapView.getProjection();
if (mLocation != null) {
mMapCoords=pj.toPixels(point, null);
final float radius = pj.metersToEquatorPixels(mLocation.getAccuracy());
this.mCirclePaint.setAntiAlias(true);
this.mCirclePaint.setARGB(35, 131, 182, 222);
this.mCirclePaint.setAlpha(50);
this.mCirclePaint.setStyle(Style.FILL);
canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint);
this.mCirclePaint.setARGB(225, 131, 182, 222);
this.mCirclePaint.setAlpha(150);
this.mCirclePaint.setStyle(Style.STROKE);
canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint);
canvas.drawBitmap(gps_marker, mMapCoords.x-gps_marker_CENTER_X, mMapCoords.y-gps_marker_CENTER_Y, this.mPaint);
}
}

}

阅读全文

与android指南针开发相关的资料

热点内容
女主胸大的H电影 浏览:877
小女孩那个电影叫什么 浏览:58
中越战争电影在哪看 浏览:896
成龙电影国语版全部 浏览:199
如何入侵网页服务器修改帐号 浏览:646
陕西物联网数显钟服务器云主机 浏览:279
原版3d是国语吗 浏览:926
程序员勇敢的第一步 浏览:160
安卓车载音乐什么格式 浏览:432
rin演过的电影 浏览:149
telnet命令登陆 浏览:328
不同文件夹名字怎么找 浏览:242
邵氏风花雪月老电影 浏览:997
php多表批量导入 浏览:50
免费理论电影大全 浏览:874
法国两男一女电影 浏览:292
有一部电影叫什么湖泊 浏览:83
大尺度电影床戏视频 浏览:672
压缩机线圈烧了可以修吗 浏览:783
cctv5加密收费吗 浏览:211