【问题标题】:How update user's current location in google map如何在谷歌地图中更新用户的当前位置
【发布时间】:2011-05-17 13:27:07
【问题描述】:

朋友们好 我想在谷歌地图中显示用户的当前位置,并在地图中添加他的位置标记,我如何每秒更新他们在谷歌地图中的位置..???

【问题讨论】:

    标签: android google-maps gps


    【解决方案1】:
    myLocationOverlay = new MyLocationOverlay(this, mapView); 
        mapView.getOverlays().add(myLocationOverlay); 
        myLocationOverlay.enableMyLocation(); 
        myLocationOverlay.runOnFirstFix(addfirststandort);
    

    【讨论】:

      【解决方案2】:

      java 文件

      public class MYGIRNE extends FragmentActivity {
      
          GoogleMap map;
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.mygirne);
      
      
              SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
      
              // Getting Map for the SupportMapFragment
              map = fm.getMap();
      
              if(map!=null){
      
                  // Enable MyLocation Button in the Map
                  map.setMyLocationEnabled(true);
               LocationManager manager=(LocationManager) getSystemService(LOCATION_SERVICE);
                  Criteria criteria=new Criteria();
                  String provider =manager.getBestProvider(criteria, true);
                  Location cloc=manager.getLastKnownLocation(provider);
                  double lat=0;
                  double lng =0;
                   lat =cloc.getLatitude();
                   lng= cloc.getLongitude();
                  LatLng latlng = new LatLng (lat,lng);
                  map.moveCamera(CameraUpdateFactory.newLatLng(latlng));
                 map.animateCamera(CameraUpdateFactory.zoomTo(15));
                 map.addMarker(new MarkerOptions()
                   .title("Your Current Location")
                  .position(latlng));
                  .icon(BitmapDescriptorFactory.defaultMarker(
                            BitmapDescriptorFactory.HUE_AZURE)));
      }
      }
      

      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"
          android:paddingBottom="@dimen/activity_vertical_margin"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:paddingTop="@dimen/activity_vertical_margin"
          tools:context="com.firsttry.cyptour.MYGIRNE" >
      
          <fragment
              android:id="@+id/map"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              class="com.google.android.gms.maps.SupportMapFragment" />
      
      </RelativeLayout>
      

      在清单文件中也包含以下内容

      <meta-data
                  android:name="com.google.android.maps.v2.API_KEY"
                  android:value="enter your APIKEY" />
              <meta-data
                  android:name="com.google.android.gms.version"
                  android:value="@integer/google_play_services_version" />
      

      这段代码应该是应用程序的一个元素

      然后在清单文件的使用权限下包含它

      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
          <uses-permission android:name="android.permission.INTERNET" />
          <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
          <!-- External storage for caching. -->
          <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
          <!-- My Location -->
          <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
          <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
          <!-- Maps API needs OpenGL ES 2.0. -->
          <uses-feature
              android:glEsVersion="0x00020000"
              android:required="true" />
      

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多