Java 当我的当前位置在2个或更多圆圈内时,如何在谷歌地图android中获得圆圈外最短路径的方向?
如果蓝色圆点是当前位置,如何获得圆外最近位置的方向 [ 如何仅在半径2000m的当前位置周围显示标记?我已将映射lanslide存储在数据库中,并在应用程序启动时显示,加载这些标记需要7-9秒。现在,我只需在当前位置周围显示,以便应用程序顺利运行 [这些是lanslide的映射点] 我正在做我的最后一个项目,我有一个功能,这是非常困难的 在我的android项目中,我在android上制作了一个关于lanslide灾难的警告应用程序,我做了lanslide位置的点映射,收集了大约150对晶格和经度,并将其放到数据库中 我假设如果用户在一个圆圈内,他们在lanslide位置,他们不安全 红色区域半径为距圆心2KM。 橙色区域半径为距圆心1公里。 黄色区域半径为距圆心500m 当应用程序启动时,地图将显示,并将相机动画设置到我的当前位置。 然后应用程序会告诉用户他们是否安全。 如果用户在圈外,那么用户是安全的。但是, 如果当前位置在圆圈内,则用户不安全。 当用户不安全时,应用程序将给出圆圈外最短路径的方向 我的应用程序几乎完成了,除了最后一个功能,我不知道该怎么做 应用程序如何给出圆外最短路径的方向 不幸的是,如果当前位置在3个或更多的圆圈内,应用程序如何为用户获得指向最短外圆圈的方向?谷歌的libarry i可以用来解决这个问题吗 如何在多个圆圈外获得方向?请帮助我 这是我的代码: 公共类menumap扩展了mapreadycallback上的片段实现{ 私有静态菜单映射实例=nullJava 当我的当前位置在2个或更多圆圈内时,如何在谷歌地图android中获得圆圈外最短路径的方向?,java,android,google-maps,geometry,Java,Android,Google Maps,Geometry,如果蓝色圆点是当前位置,如何获得圆外最近位置的方向 [ 如何仅在半径2000m的当前位置周围显示标记?我已将映射lanslide存储在数据库中,并在应用程序启动时显示,加载这些标记需要7-9秒。现在,我只需在当前位置周围显示,以便应用程序顺利运行 [这些是lanslide的映射点] 我正在做我的最后一个项目,我有一个功能,这是非常困难的 在我的android项目中,我在android上制作了一个关于lanslide灾难的警告应用程序,我做了lanslide位置的点映射,收集了大约150对晶格和
private SupportMapFragment sMapFragment;
private MapView mMapView;
SupportMapFragment mapFragment;
private GoogleMap mMap;
private String[] id, desa, status_des;
boolean markerD[];
private Double latitude, longitude;
private Circle mCircle;
private Marker mMarker;
LatLng lokasisekarang;
boolean mapReady = false;
private GoogleApiClient client;
private GoogleApiClient client2;
public static MenuMaps getInstance() {
if (instance == null) {
instance = new MenuMaps();
Log.d( "MenuMaps", "getInstance");
}
return instance;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
Log.d("MenuMaps", "OnCreateView");
View inflatedView = inflater.inflate(R.layout.menu_maps, container, false);
MapsInitializer.initialize(getActivity());
mMapView = (MapView) inflatedView.findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(this);
Button btnMap = (Button) inflatedView.findViewById(R.id.btnMap);
btnMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapReady)
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}) ;
Button btnSatellite = (Button) inflatedView.findViewById(R.id.btnSatellite);
btnSatellite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapReady)
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
});
Button btnHybrid = (Button) inflatedView.findViewById(R.id.btnHybrid);
btnHybrid.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mapReady)
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
});
return inflatedView;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("Menu Maps");
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onResume() {
mMapView.onResume();
super.onResume();
}
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void getLokasi() {
Log.d("desaStatus", "getLokasi");
String url = "http://dharuelfshop.com/skripsi/desaStatus.php/";
StringRequest request = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("desaStatus", response);
Gson gson = new Gson();
try {
JSONObject objinduk = new JSONObject(response);
List<DesaStatus> listDesaStatus = gson.fromJson(objinduk.getString("desaStatus"), new TypeToken<List<DesaStatus>>() {
}.getType());
Circle circleTerdekat = null;
Float distanceTerdekat = null;
for (DesaStatus desaStatus : listDesaStatus
) {
Log.d("desaStatus", desaStatus.toString());
LatLng center = new LatLng(desaStatus.lat_bcn,
desaStatus.long_bcn);
MarkerOptions markerOptions = new MarkerOptions()
.position(center)
.title("Desa : " + desaStatus.nama_des)
.snippet("Status : " + desaStatus.jenis_status)
.icon(BitmapDescriptorFactory
.defaultMarker(desaStatus.kode_warna));
mMarker = mMap.addMarker(markerOptions);
CircleOptions CircleOptions = new CircleOptions()
.center(center)
.radius(desaStatus.radius)//in meters
.strokeColor(Color.parseColor(desaStatus.warna_radius))
.strokeWidth(2)
.fillColor(Color.parseColor(desaStatus.warna_radius));
mCircle = mMap.addCircle(CircleOptions);
//hitung distance dan Status circle
float[] distance = new float[2];
Location.distanceBetween( lokasisekarang.latitude, lokasisekarang.longitude,
mCircle.getCenter().latitude, mCircle.getCenter().longitude, distance);
if (circleTerdekat == null) {
circleTerdekat = mCircle;
distanceTerdekat = distance[0];
} else {
if (distance[0] < distanceTerdekat ) {
distanceTerdekat = distance[0];
circleTerdekat = mCircle;
}
}
}
Log.d("circleTerdekat", "center: " + circleTerdekat.getCenter().latitude + " " + circleTerdekat.getCenter().longitude );
if( distanceTerdekat > circleTerdekat.getRadius() ){
Toast.makeText(getContext(), "You are safe, distance from center: " + distanceTerdekat + " radius: " + circleTerdekat.getRadius(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getContext(), "You are not safe, distance from center: " + distanceTerdekat + " radius: " + circleTerdekat.getRadius() , Toast.LENGTH_LONG).show();
}
} catch (JSONException error) {
Log.d("desaStatusError", error.toString());
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Error woy");
//Message
builder.setMessage("Error " + error); //+ error diganti sama (VolleyError error)
//Message
//builder.setIcon()
builder.setPositiveButton("Refreshh", new DialogInterface.OnClickListener() {
@Override //O nya huruf gede
public void onClick(DialogInterface dialog, int which) {
getLokasi();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
// menambah request ke request queue
VolleyRequest.getInstance().addToRequestQueue(request);
}
public void getCurrentLocation() {
GpsTracker gps = new GpsTracker(getActivity());
if (gps.canGetLocation()) { // gps enabled
//Getting longitude and latitude
latitude = gps.getLatitude();
longitude = gps.getLongitude();
lokasisekarang = new LatLng(latitude, longitude);
drawMarkerWithCircle(lokasisekarang);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(lokasisekarang, 14f));
// \n is for new line
//Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}
else {
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
gps.showSettingsAlert();
//gps.stopUsingGPS();
}
}
private void drawMarkerWithCircle(LatLng lokasisekarang) {
MarkerOptions markerOptions = new MarkerOptions()
.position(lokasisekarang)
.title("You are here")
.snippet("here")
.icon(BitmapDescriptorFactory
.defaultMarker(HUE_BLUE));
mMarker = mMap.addMarker(markerOptions);
CircleOptions circleOptions = new CircleOptions()
.center(lokasisekarang)
.radius(2000)
.strokeWidth(2)
.strokeColor(Color.BLUE)
.fillColor(Color.parseColor("#500084d3"));
mMap.addCircle(circleOptions);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mapReady = true;
mMap = googleMap;
getCurrentLocation();
getLokasi();
if (ActivityCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true); // buat enable button location
}}
private-supportmappfragment-sMapFragment;
私人地图视图;
SupportMapFragment-mapFragment;
私有谷歌地图;
私有字符串[]id、desa、状态\ des;
布尔markerD[];
私人双纬度、经度;
私人圈子;
专用标记器;
LatLng lokasisekarang;
布尔mapredy=false;
私人谷歌客户;
私人GoogleapClient客户2;
公共静态菜单映射getInstance(){
if(实例==null){
实例=新菜单映射();
Log.d(“menumap”、“getInstance”);
}
返回实例;
}
@可空
@凌驾
创建视图时的公共视图(LayoutFlater充气机、@Nullable ViewGroup容器、@Nullable Bundle savedInstanceState)
{
Log.d(“菜单映射”、“OnCreateView”);
视图充气视图=充气机充气(R.layout.menu\u maps,container,false);
初始化(getActivity());
mMapView=(MapView)充气视图.findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(this);
按钮btnMap=(按钮)充气视图.findViewById(R.id.btnMap);
btnMap.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(mapReady)
mMap.setMapType(GoogleMap.MAP\u TYPE\u NORMAL);
}
}) ;
按钮btnSatellite=(按钮)充气视图.findViewById(R.id.btnSatellite);
btnSatellite.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(mapReady)
mMap.setMapType(GoogleMap.MAP_TYPE_卫星);
}
});
按钮btnHybrid=(按钮)充气视图.findViewById(R.id.btnHybrid);
btnHybrid.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(mapReady)
mMap.setMapType(GoogleMap.MAP\u TYPE\u HYBRID);
}
});
返回充气视图;
}
@凌驾
已创建视图上的公共void(视图,@Nullable Bundle savedInstanceState){
super.onViewCreated(视图,savedInstanceState);
getActivity().setTitle(“菜单映射”);
}
@凌驾
public void onStart(){
super.onStart();
}
@凌驾
公共void onStop(){
super.onStop();
}
@凌驾
恢复时公开作废(){
mMapView.onResume();
super.onResume();
}
@凌驾
公共无效暂停(){
super.onPause();
mMapView.onPause();
}
@凌驾
公共空间{
super.ondestory();
mMapView.onDestroy();
}
@凌驾
public void onLowMemory(){
super.onLowMemory();
mMapView.onLowMemory();
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
公开无效getLokasi(){
日志d(“desaStatus”、“getLokasi”);
字符串url=”http://dharuelfshop.com/skripsi/desaStatus.php/";
StringRequest=newStringRequest(url,new Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
日志d(“状态”,响应);
Gson Gson=新的Gson();
试一试{
JSONObject objinduk=新JSONObject(响应);
List listDesaStatus=gson.fromJson(objinduk.getString(“desaStatus”),新类型令牌(){
}.getType());
圆圈circleTerdekat=null;
Float distanceTerdekat=null;
对于(DesaStatus DesaStatus:listDesaStatus
) {
Log.d(“desaStatus”,desaStatus.toString());
LatLng中心=新LatLng(desaStatus.lat_bcn,
desaStatus.long_bcn);
MarkerOptions MarkerOptions=新MarkerOptions()
.位置(中间)
标题(“Desa:+desaStatus.nama_des)
.snippet(“状态: