我是android開發新手。我試圖在我的應用地圖中添加Google標記,但不會顯示。我可以設置一個標記,如果標記的lat是一個雙精度數,但是當我將API數據放入它時,它不會顯示。任何建議?非常感謝。Android谷歌地圖標記不會顯示
@Override
public void onMapReady(final GoogleMap googleMap) {
this.googleMap = googleMap;
// Add a marker in Sydney and move the camera
getLocation();
// This marker will show at my app screen !
LatLng latLng = new LatLng(24.9992666, 121.5082287);
googleMap.addMarker(new MarkerOptions().position(latLng)
.title("This is office Marker")
);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 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;
}
this.googleMap.setMyLocationEnabled(true);
HttpUtil.sendHttpRequest("http://113.10.198.159/appapi/getWIFIList", new HttpCallbackListener() {
@Override
public void onFinish(String response) {
Gson gson = new Gson();
JsonBean jsonBean = gson.fromJson(response, JsonBean.class);
Log.d(TAG, "【】【id】【】" + jsonBean.getResult().get(0).getId());
Log.d(TAG, "【】【merchant_id】【】" + jsonBean.getResult().get(0).getMerchant_id());
Log.d(TAG, "【】【merchant_name】【】" + jsonBean.getResult().get(0).getMerchant_name());
Log.d(TAG, "【】【city】【】" + jsonBean.getResult().get(0).getCity());
Log.d(TAG, "【】【area】【】" + jsonBean.getResult().get(0).getArea());
Log.d(TAG, "【】【address】【】" + jsonBean.getResult().get(0).getAddress());
Log.d(TAG, "【】【lat】【】" + jsonBean.getResult().get(0).getLat());
Log.d(TAG, "【】【lng】【】" + jsonBean.getResult().get(0).getLng());
Log.d(TAG, "【】【addTime】【】" + jsonBean.getResult().get(0).getAddTime());
Log.d(TAG, "【】【dlat】【】" + jsonBean.getResult().get(0).getDlat());
Log.d(TAG, "【】【dlng】【】" + jsonBean.getResult().get(0).getDlng());
Log.d(TAG, "【】【wificode】【】" + jsonBean.getResult().get(0).getWificode());
Log.d(TAG, "【】【upstream】【】" + jsonBean.getResult().get(0).getUpstream());
Log.d(TAG, "【】【downstream】【】" + jsonBean.getResult().get(0).getDownstream());
//// This marker can not show at my app screen
LatLng latLng = new LatLng(jsonBean.getResult().get(0).getDlat(), jsonBean.getResult().get(0).getDlng());
Marker marker = googleMap.addMarker(new MarkerOptions().position(latLng)
.title("This is Test Marker")
);
}
@Override
public void onError(Exception e) {
}
});
}
public class HttpUtil {
public static void sendHttpRequest(final String address, final HttpCallbackListener listener) {
new Thread(new Runnable() {
@Override
public void run() {
try {
OkHttpClient client = new OkHttpClient();
String s1 = "lat";
String s2 = "24.9992666";
String s3 = "lng";
String s4 = "121.5082287";
RequestBody requestBody = new FormBody.Builder()
.add(s1, s2)
.add(s3, s4)
.build();
Request request = new Request.Builder()
.url(address)
.post(requestBody) //post
.build();
Response response = client.newCall(request).execute();
String responseData = response.body().string();
if (listener != null) {
// onFinish() method
listener.onFinish(responseData);
}
} catch (Exception e) {
if (listener != null) {
// onError() method
listener.onError(e);
}
}
}
}).start();
}
}
代碼請。謝謝。 http://stackoverflow.com/help/mcve –
請添加代碼,以獲得想法你嘗試過什麼? –
@SouravGanguly這是我的代碼,這是我使用Stackoverflow時的第一個問題,對不起,我是一個新人。 – JackenLiu