【问题标题】:Get back to my app after marker click on google maps标记点击谷歌地图后返回我的应用程序
【发布时间】:2014-05-27 09:03:30
【问题描述】:

我在应用开发中遇到了问题。单击按钮后,我可以打开具有用户当前位置的 Google 地图。

location_selection.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                Location gpsLocation = appLocationService.getLocation(LocationManager.GPS_PROVIDER);
                Location nwLocation = appLocationService.getLocation(LocationManager.NETWORK_PROVIDER);

                if (gpsLocation != null) {

                    latitude = gpsLocation.getLatitude();
                    longitude = gpsLocation.getLongitude();

                } else if(nwLocation != null) {

                    latitude = nwLocation.getLatitude();
                    longitude = nwLocation.getLongitude();

                } else {

                    Toast hint = Toast.makeText(getApplicationContext(), "Please turn on GPS/Network", Toast.LENGTH_SHORT);
                    hint.show();

                }

                if(latitude != 0 && longitude != 0) {

                    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                            Uri.parse("geo:0,0?q="+latitude+","+longitude));
                    startActivity(intent);

                }

            }

        });

我想要做的是检索用户在打开谷歌地图后设置的标记的坐标和地址,并将这些数据返回到我的应用程序关闭谷歌地图。但我真的不知道该怎么做!

【问题讨论】:

    标签: android google-maps maps marker


    【解决方案1】:

    从当前位置的经纬度获取地址

    看看这个链接 https://developers.google.com/maps/documentation/geocoding/

    寻找“反向地理编码(地址查找)”可能会有所帮助

    您必须使用您的 lat 和 long 对 google Geocoding API 进行 http 调用,该 API 会检索包含您对该位置感兴趣的地址的 JSON。将 Java 中的 JSON 排序为可读文本。

    我想做的是检索坐标 我不确定你在这里的意思,因为 lat 和 long 已经在你上面的代码中了

    希望对你有帮助

    【讨论】:

    • 感谢您的回答。当我说“检索坐标”时,我的意思是我可以在当前坐标上打开地图,但我想检索用户在地图中选择的新标记的坐标及其相对地址,并使用 NEW_LATITUDE、NEW_LONGITUDE 关闭地图, ADDRESS_REFERRED_TO_THIS_NEW_LOCATION 返回我的应用程序。
    • 若要在用户点击地图时从用户那里获取坐标,请重写实现 OnMapClickListener 的 onMapClick 方法。使用这些坐标进行 Geocoding API 调用以获取地址
    猜你喜欢
    • 2012-09-27
    • 2011-01-09
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    • 2017-10-20
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多