2015-12-03 169 views
1

我已經完成了谷歌地圖在當前位置設置標記(當前經緯度/長度)。現在我想從用戶當前位置設置標記到1英里,我被困在這裏如何解決這個問題?谷歌地圖在當前位置設置標記

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

在上面的代碼中,目標位置僅需要點4緯度經度。

+0

你是指「半英里以上」 – Neji

回答

1

嘗試使用此代碼

GPSTracker gps; 

gps = new GPSTracker(SearchLocation.this); 

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

,或者您可以使用其他一些代碼,緯度,經度和使用此代碼 -

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)); 

添加這樣的一些perditions: -

<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。

相關問題