百度地图开发过程中遇到的好多好多好多问题(待更新)

1. 初次接触append函数
可以用append来为TextView显示文字
值得注意的是,append()与setText()的区别是:

  • append()函数将文字添加在已有的TextView内容之后
  • setText()是直接将TextView中的内容覆盖

StringBuilder可以多次调用append函数,用法如下

address_tv = (TextView) findViewById(R.id.address);
StringBuilder currentPosition = new StringBuilder();
            currentPosition.append("纬度:").append(location.getLatitude()).append("\t");
            currentPosition.append("经度:").append(location.getLongitude()).append("\n");
            currentPosition.append("省:").append(location.getProvince()).append("\t");
            currentPosition.append("市:").append(location.getCity()).append("\t");
            currentPosition.append("区:").append(location.getDistrict()).append("\n");
            currentPosition.append("街道:").append(location.getStreet()).append("\t");
            currentPosition.append("门牌号:").append(location.getStreetNumber());
 address_tv.setText(currentPosition);

并最后将其一次性赋值给TextView。
2.(百度地图sdk)经纬度以外城市、街道信息等的显示
若缺少注释所标识的代码,只可获得经纬度,无法获取其余信息,可参考上一段代码

LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true); // 打开gps
        option.setCoorType("bd09ll"); // 设置坐标类型
        option.setScanSpan(1000);
        option.setIsNeedAddress(true);//若不加此句,将无法显示省市街道等信息
        mLocClient.setLocOption(option);

3.自定义Dialog时主题的设定问题
在写dialog时,自定义了一个layout,但是会弹出的dialog会出现一个莫名其妙的边,经资料查阅发现是style的问题,解决方案如下:
在styles.xml中添加新的style

<style name="StyleDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        //设置背景为透明
        <item name="android:windowNoTitle">true</item>
        //  设置无标题
        <item name="android:backgroundDimEnabled">true</item>
        //  此属性可以翻译为 是否允许对话框的背景变暗?如果允许背景就变暗了。
    </style>

在java文件中添加如下语句(其中,dialog也可以在manifest中改变主题)

builder = new AlertDialog.Builder(mContext,R.style.StyleDialog);

自己写的dialog是介个样子的

public void dialogShow1(StringBuilder currentPosition,Context mContext){
        builder = new AlertDialog.Builder(mContext,R.style.StyleDialog);
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View view = inflater.inflate(R.layout.dialog1,null);
        TextView address = (TextView)view.findViewById(R.id.tv_address);
        address.setText(currentPosition);
        Button dialog_close = (Button) view.findViewById(R.id.close);
        final Dialog dialog = builder.create();
        dialog.show();
        dialog.getWindow().setContentView(view);
        dialog_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

    }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值