【问题标题】:Android how can I get coordinates and add it to link automaticallyAndroid如何获取坐标并将其自动添加到链接
【发布时间】:2023-04-06 01:02:01
【问题描述】:

我正在开发一个组织我的地址的应用程序,我希望实现以下目标:

当我点击添加地址按钮时,会出现两个文本框,NameLink。我希望Link 文本框自动获取当前位置并将坐标添加到此 URL:

http://maps.google.com/maps?q=

例如这是坐标27.123456,49.123456,所以最终的结果是这样的:

http://maps.google.com/maps?q=27.123456,49.123456

我搜索了几个小时,但我所能做的就是获取当前位置坐标。所以请各位大神帮忙,我会非常感激的。

*** 更新这是现在的问题:

public void buildLink(float textLatt, float textLot) {
return String.format("http://maps.google.com/maps?q=%f,%f", textLatt, textLot);
}

【问题讨论】:

    标签: java android string-concatenation


    【解决方案1】:

    如果你有坐标,它应该是一个简单的字符串连接并在编辑文本上设置值。你可以做类似(伪代码)

    EditText et = findView(R.id.mylink)
    et.setText(buildLink(lat, long))
    

    -

    void buildLink(float lat, float long){
        return String.format("http://maps.google.com/maps?q=%f,%f", lat,long)
    }
    

    【讨论】:

    • 感谢您的帮助,我正在尝试,但我无法让它工作,所以现在我被困在这段代码中:public void buildLink(float textLatt, float textLot) { return String .format("maps.google.com/maps?q=%f,%f", textLatt, textLot);
    • 我已经更新了主要问题,请您检查一下吗?
    【解决方案2】:
    txtmylink.setText(
        String.valueOf("http://maps.google.com/maps?q=") + 
        String.valueOf(mLastLocation.getLatitude()) +
        String.valueOf(",") + 
        String.valueOf(mLastLocation.getLongitude()));
    

    【讨论】:

    • 虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高​​答案的长期价值。
    猜你喜欢
    • 2013-12-24
    • 1970-01-01
    • 2018-05-04
    • 2014-06-16
    • 2021-12-29
    • 2012-08-16
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多