【发布时间】:2017-08-31 07:41:33
【问题描述】:
我有一个从服务器获取通知的应用程序,当应用程序在后台并点击通知时,地图活动将打开并应在地图中显示从通知中获取纬度和经度的标记。我的代码中的每个日志都可以工作,直到代码到达也添加标记,但它没有显示任何内容。这是我的代码:
@Override
public void onConnected(Bundle bundle) {
Log.e("onConnect", "here");
.
.
.
ShowUserRequest();
}
显示用户请求():
public void ShowUserRequest(){
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
//bundle must contain all info sent in "data" field of the notification
Log.e("bundle", bundle.getString("msg")+"");
try {
if(bundle.getString("msg") != null){
JSONArray jsonArray = new JSONArray(bundle.getString("msg"));
JSONObject jsonObject = jsonArray.getJSONObject(0);
name.setText(jsonObject.getString("customer_name"));
phone.setText(jsonObject.getString("phone"));
description.setText(jsonObject.getString("description"));
address.setText(jsonObject.getString("address"));
user_latitude = jsonObject.getDouble("latitude");
user_longitude = jsonObject.getDouble("longitude");
Log.e("lat_lang",user_latitude + user_longitude+"");
ShowUserLocation(user_latitude,user_longitude,jsonObject.getString("customer_name"),
jsonObject.getString("phone"),jsonObject.getString("description"),jsonObject.getString("address"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
显示用户位置():
public void ShowUserLocation(double latitude , double longitude , final String name_st ,final String phone_st , final String description_st , final String address_st){
Log.e("dataaa",latitude + " " + longitude + " " +name_st + " " + phone_st + " " + description_st + " " + address_st + "");
if(name_st != null && !name_st.equals("") && !name_st.equals("null") ){
name.setText(name_st);
}
if(phone_st != null && !phone_st.equals("") && !phone_st.equals("null")) {
phone.setText(phone_st);
}
if(description_st != null && !description_st.equals("") && !description_st.equals("null") ) {
description.setText(description_st);
}
if(address_st != null && !address_st.equals("") && !address_st.equals("null") ) {
address.setText(address_st);
}
LatLng UserlatLng = new LatLng(latitude, longitude);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(UserlatLng);
markerOptions.title(name_st);
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 18.0f));
userLocationMarker = googleMap.addMarker(markerOptions);
}
【问题讨论】:
标签: android google-maps notifications google-maps-markers intentfilter