当通知进入后台时,谷歌地图中的addMarker

时间:2017-08-31 07:41:34

标签: android google-maps notifications google-maps-markers intentfilter

我有一个应用程序从服务器获取通知,当应用程序在后台并点击通知时,地图活动打开并应在地图中显示从通知中获取经度和纬度的标记。我的代码中的每个日志工作,直到代码到达也添加标记,但它没有显示任何内容。我的代码是:

 @Override
public void onConnected(Bundle bundle) {

    Log.e("onConnect", "here");

       .
       .
       .

    ShowUserRequest();

}

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

        }

}

ShowUserLocation():

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

   }

1 个答案:

答案 0 :(得分:1)

<manifest>