android - 我有一个带有特定位置图标的 map View 。如何添加 mylocationoverlay?

标签 android dictionary location

我已经能够根据在线教程创建一个 mapview。现在一切正常。 但是,我想了解如何添加我的当前位置?我已经完成了几个教程,但无法理解它。有任何想法吗?这是我将要使用的代码。

主 Activity .java

 package com.example.midlandtest;

     import android.app.Activity;
     import android.location.Location;
     import android.os.Bundle;
     import android.view.Menu;
     import com.google.android.gms.maps.CameraUpdateFactory;
     import com.google.android.gms.maps.GoogleMap;
     import com.google.android.gms.maps.MapFragment;
     import com.google.android.gms.maps.model.BitmapDescriptorFactory;
     import com.google.android.gms.maps.model.LatLng;
     import com.google.android.gms.maps.model.LatLngBounds;
     import com.google.android.gms.maps.model.Marker;
     import com.google.android.gms.maps.model.MarkerOptions;

     public class MainActivity extends Activity {
       static final LatLng HAMBURG = new LatLng(53.28000, -7.49000);
       static final LatLng KIEL = new LatLng(53.274823, -7.492655);
     private GoogleMap map;

     @Override
      protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
        .getMap();
     Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
        .title("Tullamore"));
     Marker kiel = map.addMarker(new MarkerOptions()
        .position(KIEL)
        .title("Midlands Regional Authority")
        .snippet("Hey :-)")
        .icon(BitmapDescriptorFactory
            .fromResource(R.drawable.ic_launcher)));

    // Move the camera instantly to hamburg with a zoom of 15.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

    // Zoom in, animating the camera.
    map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
     }

      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
        }

     }

list .xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.midlandtest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="17" />

    <permission
        android:name="com.example.midlandtest.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <uses-permission android:name="com.example.midlandtest.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
       <uses-permission 
        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.midlandtest.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="-" />
      </application>

      </manifest> 

主.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />

 </RelativeLayout>  

最佳答案

关于android - 我有一个带有特定位置图标的 map View 。如何添加 mylocationoverlay?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15160953/

相关文章:

Android - GoogleApiClient 实例在 IntentService 中的 .connect() 和 onConnected() 之间丢失

ios - CLLocationManager 是如何获取位置的?

android - 打开/关闭移动蜂窝数据(移动互联网)时如何触发 BroadcastReceiver

Android:使用处理程序和 postDelayed() 发出问题

android - 在android中的EditText上输入时如何过滤ListView数据

python - 将 Python 字典写入 CSV,其中键 = 列,值 = 行

python - 如何在 Python 的字典理解中创建值列表

android - Android 中带有 CursorAdapter 的 ORMLite

python - 使用 python 比较字典

Java JTextArea、JLabel 和其他组件 : How to set Location