Google Map在当前位置设置标记

时间:2015-12-03 06:20:11

标签: android

我已经完成了当前位置(当前纬度/长度)设置标记上的谷歌地图。现在我想将用户当前位置的标记设置为1英里,我被困在这个如何解决这个问题? / p>

for(LatLng point1 : new LatLng[]{point1, point2, point3, point4})
    {                               
    targetLocation.setLatitude(point1.latitude);
    targetLocation.setLongitude(point1.longitude);
    if(currentBestLocation.distanceTo(targetLocation) < 800) 
        {}

在上面的代码中,目标位置仅采用经度4经度。

1 个答案:

答案 0 :(得分:1)

尝试使用此代码

GPSTracker gps;

gps = new GPSTracker(SearchLocation.this);

    if (gps.canGetLocation()) {
        usersearchlat = gps.getLatitude();
        usersearchlong = gps.getLongitude();
    } else {
        gps.showSettingsAlert();
    }

或者您可以使用其他一些代码用于lat,long并使用此代码 -

    mMapView.onResume();// needed to get the map to display immediately

    try {
        MapsInitializer.initialize(getApplicationContext()
                .getApplicationContext());

        googleMap = mMapView.getMap();

        googleMap.setMyLocationEnabled(true);
        googleMap.setMapType(googleMap.MAP_TYPE_HYBRID);
        googleMap.getUiSettings().setMyLocationButtonEnabled(true);
        googleMap.getUiSettings().setCompassEnabled(true);
        googleMap.getUiSettings().setZoomControlsEnabled(true);

        googleMap.getUiSettings().setRotateGesturesEnabled(true);

    } catch (Exception e) {
        e.printStackTrace();
    }
    googleMap.addMarker(marker);
                CameraPosition cameraPosition = new CameraPosition.Builder()
                        .target(new LatLng(usersearchlat, usersearchlong))
                        .zoom(12).build();
                googleMap.animateCamera(CameraUpdateFactory
                        .newCameraPosition(cameraPosition));

添加一些这样的例外: -

 <uses-permission android:name="android.permisssion.ACCESS_FINE_LOCATION">
  </uses-permission>
  <uses-permission
  android:name="android.permisssion.ACCESS_COARSE_LOCATION"></uses-
  permission>
 <uses-permission android:name="android.permisssion.INTERNET"/>

ACCESS_COARSE_LOCATION。

相关问题