如何在安卓工作室中显示半径为2个标记的显示距离



Heloo我是安卓工作室的新手,我做了一个名为BTS定位器的项目,在2天内混淆了两个2标记显示距离。所以圆圈中心的标记是抱怨,另一个是防弹少年团。然后我想向防弹少年团显示距离投诉,有人可以帮我吗? 在此处输入图像描述

所以这是我的地图活动

package com.example.jody_pc.btslocator;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
String lat,lng;
Double latitude,longitude;
private Circle mCircle;
private String[] id,vendor,cellname,tower_id,total_tilt,site_name,bsc_rnc,lac,ci,bcch,bsid_rncid,site_id,dir,ant_height,status_site,cell_type,cluster_name,band,kecamatan,kabupaten;
int numData;
LatLng latLng[];
Boolean markerD[];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Bundle b = getIntent().getExtras();
lat = b.getString("lat");
lng = b.getString("lng");

latitude = Double.parseDouble(lat);
longitude = Double.parseDouble(lng);

sekitar();
}

/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng latlng = new LatLng(latitude, longitude);

mMap.addMarker(new MarkerOptions().position(latlng));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 14.5f));
drawMarkerWithCircle(latlng);
//mMap.setOnInfoWindowClickListener(this);
}
private void drawMarkerWithCircle(LatLng latlng) {
double radiusInMeters = 2500.0;
int strokeColor = 0xffff0000; //red outline
int shadeColor = 0x44ff0000; //opaque red fill
CircleOptions circleOptions = new CircleOptions().center(latlng).radius(radiusInMeters).fillColor(shadeColor).strokeColor(strokeColor).strokeWidth(8);
mCircle = mMap.addCircle(circleOptions);
}
private void sekitar(){
String url = "http://bts.telkompolines.com/sekitar.php?lat="+lat+"&&lng="+lng;
/*String url = "https://devonly.000webhostapp.com/conn.php";*/
JsonArrayRequest request = new JsonArrayRequest
(Request.Method.GET, url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
numData = response.length();
Log.d("DEBUG_", "Parse JSON");
latLng = new LatLng[numData];
markerD = new Boolean[numData];
/*nama = new String[numData];*/
vendor = new String[numData];
site_name = new String[numData];
tower_id = new String[numData];
bsc_rnc = new String[numData];
lac = new String[numData];
ci = new String[numData];
bcch = new String[numData];
bsid_rncid = new String[numData];
site_id = new String[numData];
dir = new String[numData];
ant_height = new String[numData];
total_tilt = new String[numData];
status_site = new String[numData];
cell_type = new String[numData];
cluster_name = new String[numData];
band = new String[numData];
kecamatan = new String[numData];
kabupaten = new String[numData];
id = new String[numData];
cellname = new String[numData];
for (int i = 0; i < numData; i++) {
JSONObject data = null;
try {
data = response.getJSONObject(i);
id[i] = data.getString("id");
latLng[i] = new LatLng(data.getDouble("lat"),
data.getDouble("lng"));
vendor[i] = data.getString("vendor");
cellname[i] = data.getString("cellname");
kabupaten [i] = data.getString("kabupaten");
tower_id [i] = data.getString("tower_id");
bsc_rnc [i] = data.getString("tower_id");
lac [i] = data.getString("lac");
ci [i] = data.getString("ci");
bcch [i] = data.getString("bcch");
bsid_rncid [i] = data.getString("bsid_rncid");
site_id [i] = data.getString("site_id");
site_name [i] = data.getString("site_name");
dir [i] = data.getString("dir");
ant_height [i] = data.getString("ant_height");
total_tilt [i] = data.getString("total_tilt");
status_site [i] = data.getString("status_site");
cell_type [i] = data.getString("cell_type");
cluster_name [i] = data.getString("cluster_name");
band [i] = data.getString("band");
kecamatan [i] = data.getString("kecamatan");

markerD[i] = false;
mMap.addMarker(new MarkerOptions()
.position(latLng[i])
.title(site_name[i]));
final int finalI = i;
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Intent detail  = new Intent(getApplicationContext(), DetailActivity.class);
Bundle b = new Bundle();
LatLng position = marker.getPosition();
/*Double x = position.latitude;
Double y = position.longitude;
String lat = Double.toString(x);
String lng = Double.toString(y);*/
b.putString("cellname", cellname[finalI]);
b.putString("id", id [finalI]);
b.putString("vendor", vendor[finalI]);
b.putString("kabupaten", kabupaten[finalI]);
b.putString("tower_id", tower_id[finalI]);
b.putString("bsc_rnc", bsc_rnc[finalI]);
b.putString("lac", lac[finalI]);
b.putString("ci", ci[finalI]);
b.putString("bcch", bcch[finalI]);
b.putString("bsid_rncid", bsid_rncid[finalI]);
b.putString("site_id", site_id[finalI]);
b.putString("site_name", site_name[finalI]);
b.putString("dir", dir[finalI]);
b.putString("ant_height", ant_height[finalI]);
b.putString("total_tilt", total_tilt[finalI]);
b.putString("status_site", status_site[finalI]);
b.putString("cell_type", cell_type[finalI]);
b.putString("cluster_name", cluster_name[finalI]);
b.putString("band", band[finalI]);
b.putString("kecamatan", kecamatan[finalI]);
b.putString("lat", String.valueOf(position.latitude).toString());
b.putString("lng", String.valueOf(position.longitude).toString());
detail.putExtras(b);
startActivity(detail);
return false;
}
});

} catch (JSONException e) {
e.printStackTrace();
}
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng[i], 15.5f));
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
AlertDialog.Builder builder = new AlertDialog.Builder(MapsActivity.this);
builder.setTitle("Error!");
builder.setMessage("No Internet Connection");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setPositiveButton("Refresh", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sekitar();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
Volley.newRequestQueue(this).add(request);
}

}

应使用 Location.distanceBetween 方法计算中心点与单击的标记之间的距离(以米为单位(。

在您的onMarkerClick()中执行以下操作(假设您想像传递所有其他 BTS 相关数据一样传递距离信息(:

float[] results = new float[3];
Location.distanceBetween(self.latitude, self.longitude, position.latitude, position.longitude, results);
b.putString("distance_in_meters", String.valueOf(results[0]));

相关内容

  • 没有找到相关文章

最新更新