设为首页 加入收藏

TOP

android studio高德地图的显示于定位(附带逆地理编码围栏)(四)
2017-10-12 10:03:50 】 浏览:4816
Tags:android studio 高德 地图 显示 定位 附带 地理 编码 围栏
.show(); } } /** * 响应逆地理编码围栏 */ public void getAddress(final LatLonPoint latLonPoint) { RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 100, GeocodeSearch.AMAP);// 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是网络 坐标系还是GPS原生坐标系 geocoderSearch.getFromLocationAsyn(query);// 设置同步逆地理编码请求 } /** * 地理编码查询回调 */ @Override public void onGeocodeSearched(GeocodeResult result, int rCode) { } /** * 逆地理编码回调 */ @Override public void onRegeocodeSearched(RegeocodeResult result, int rCode) { if (rCode == 1000) { if (result != null && result.getRegeocodeAddress() != null && result.getRegeocodeAddress().getFormatAddress() != null) { Toast.makeText(MainActivity.this,result.getRegeocodeAddress().getFormatAddress() + "附近",Toast.LENGTH_LONG).show(); aMap.animateCamera(CameraUpdateFactory.newLatLngZoom( AMapUtil.convertToLatLng(latLonPoint), 15)); geoMarker.setPosition(AMapUtil.convertToLatLng(latLonPoint)); } else { } } else { } } @Override public void onResume() { super.onResume(); mapView.onResume(); } /** * 方法必须重写 */ @Override public void onPause() { super.onPause(); mapView.onPause(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mapView.onSaveInstanceState(outState); } @Override public void onDestroy() { super.onDestroy(); mapView.onDestroy(); } }

在同级的文件下建立自己的类方法,调用到主代码中

AMapUtil代码为:

public class AMapUtil {
    /**
     * 判断edittext是否null
     */
    public static String checkEditText(EditText editText) {
        if (editText != null && editText.getText() != null
                && !(editText.getText().toString().trim().equals(""))) {
            return editText.getText().toString().trim();
        } else {
            return "";
        }
    }

    public static Spanned stringToSpan(String src) {
        return src == null ? null : Html.fromHtml(src.replace("\n", "<br />"));
    }

    public static String colorFont(String src, String color) {
        StringBuffer strBuf = new StringBuffer();

        strBuf.append("<font color=").append(color).append(">").append(src)
                .append("</font>");
        return strBuf.toString();
    }

    public static String makeHtmlNewLine() {
        return "<br />";
    }

    public static String makeHtmlSpace(int number) {
        final String space = " ";
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < number; i++) {
            result.append(space);
        }
        return result.toString();
    }

    public static String getFriendlyLength(int lenMeter) {
        if (lenMeter > 10000) // 10 km
        {
            int dis = lenMeter / 1000;
            return dis + "";
        }

        if (lenMeter > 1000) {
            float dis = (float) lenMeter / 1000;
            DecimalFormat fnum = new DecimalFormat("##0.0");
            String dstr = fnum.format(dis);
            return dstr;
        }

        if (lenMeter > 100) {
            int dis = lenMeter / 50 * 50;
            return dis + "";
        }

        int dis = lenMeter / 10 * 10;
        if (dis == 0) {
            dis = 10;
        }

        return dis + "";
    }

    public static boolean IsEmptyOrNullString(String s) {
        return (s == null) || (s.trim().length() == 0);
    }

    /**
     * 把LatLng对象转化为LatLonPoint对象
     */
    public static LatLonPoint convertToLatLonPoint(LatLng latlon) {
        return new LatLonPoint(latlon.latitude, latlon.longitude);
    }

    /**
     * 把LatLonPoint对象转化为LatLon对象
     */
    public static LatLng conver
首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇一步一步实现android studio代码.. 下一篇一步一步实现android studio代码..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目