導航:首頁 > 操作系統 > 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指南針開發相關的資料

熱點內容
老男孩韓國完整版百度網盤 瀏覽:485
用箱子運水怪結果被放出來了電影 瀏覽:519
徐錦江空中飛人片名 瀏覽:164
手機免費在線看福利電影 瀏覽:457
羅麗星克萊爾經典 瀏覽:342
台灣紅羊有哪些經典電影 瀏覽:568
免下載你懂的 瀏覽:975
新建文件夾1女演員三位 瀏覽:740
不用下載就能看的視頻網站 瀏覽:330
我一個神偷硬生生把國家偷成強國 瀏覽:600
樣子是五歲小男孩和郭富城演的 瀏覽:460
韓國演員也美娜 瀏覽:898
陸離是哪部小說的主角 瀏覽:49
華娛開局佟麗婭 瀏覽:17
男男生子小說現代攻姓章 瀏覽:541
永旺星星影院影訊 瀏覽:328
李彩潭巔峰之作 瀏覽:86
彎村紅羊電影 瀏覽:157
我和我的家教老師韓國 瀏覽:102
日本經典高分電影 瀏覽:627