本文介绍了将多个标签添加到标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建了我的答案模型.在标记中还添加了标签:

Created i model like in answer.Also added tags in markers:

 MarkerTag tag = new MarkerTag();
    Marker marker = map.addMarker(new MarkerOptions()
            .position(new LatLng(47.045029, 28.861427))
            .title("Marker")
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
            .snippet("Population: 4,137,400"));
    tag.setEmail("[email protected]");
    tag.setPhoneNumber("+37369490007");
    marker.setTag(tag);
    Marker marker2 = map.addMarker(new MarkerOptions()
            .position(new LatLng(47.000327, 28.867950))
            .title("Marker")
            .snippet("Population: 4,137,400 fdfsfsfsdfsfdsfsfssfsfsfsfsfs"));
    tag.setEmail("[email protected]");
    tag.setPhoneNumber("+37368750588");
    marker2.setTag(tag);
    Marker marker3 = map.addMarker(new MarkerOptions()
            .position(new LatLng(47.024204, 28.889236))
            .title("Marker")
            .snippet("Population: 4,137,400 /n dasdasdas d"));
    tag.setEmail("[email protected]");
    tag.setPhoneNumber("+37369339092");
    marker3.setTag(tag);

并添加了我的方法:

private void makeCall(Marker marker) {
    MarkerTag tag = ((MarkerTag)marker.getTag());
    if (tag != null) {
        Intent call = new Intent(Intent.ACTION_DIAL);
        call.setData(Uri.parse("tel:" + String.valueOf(tag.getPhoneNumber())));
        startActivity(call);
    }
}
private void sendEmail(Marker marker) {
    MarkerTag tag = ((MarkerTag)marker.getTag());
    if (tag != null) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
        intent.putExtra(Intent.EXTRA_TEXT, "text");
        intent.setData(Uri.parse("email:" + String.valueOf(tag.getEmail())));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        checkAndStart(this, intent, R.string.action_settings);
    }
}

但是现在当我按下标记时,我只会得到一个数字,这个

But now when i press on markers i get just one number, this

推荐答案

.setTag()接受对象.因此,为了在其中添加更多信息,您只需要创建自己的TagObject,就可以将其称为MarkerTag;

The .setTag() accept an object. So, in order to add more information in there you just have to create your own TagObject, lets call it MarkerTag;

public class MarkerTag {


    private String email;
    private String phoneNumber;

    public MarkerTag() {

    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
}

然后,您只需将其作为标记添加到标记中即可

Then you just add it to your marker as a tag:

MarkerTag yourMarkerTag = new MarkerTag();
yourMarkerTag.setEmail("[email protected]");
yourMarkerTag.setPhoneNumber("+15552345353");
marker.setTag(yourMarkerTag);

现在要找回它,您只需确保获得正确的

Now to get it back you just have to make sure that you are getting the right

    if(null != marker.getTag()){
    if(marker.getTag() instanceof MarkerTag){
        MarkerTag yourMarkerTag = ((MarkerTag)marker.getTag());
        Toast.makeText(getActivity, yourMarkerTag.getEmail() , Toast.LENGTH_SHORT).show();
        Toast.makeText(getActivity, yourMarkerTag.getPhoneNumber() , Toast.LENGTH_SHORT).show();
    }
}

这篇关于将多个标签添加到标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 16:28