0

好吧,我有几个与这个问题相关的话题,但除了没有人提供明确的解决方案之外,我仍然没有得到逻辑。无论如何,我会尝试再次清楚地询问它并提供屏幕截图(来自示例应用程序)希望它能发挥作用。

正如您在下面看到的,谷歌地图上有一个自定义标记,我可以通过添加一个Imageview. 在上面的地图上有一个TextView。当地图上的标记位置发生变化时,地址会动态变化。但是我们不是拖放它固定在中心且不可拖动的标记。我们正在做的只是平移地图。当我们停止平移时,标记会显示在地图上的某处,并迅速显示为Textview.

我可以通过处理来更改地址,onMarkerDragEnd()但这是另一种情况。也没有 GPS 连接我猜它正在screenPosition使用类将视图转换为纬度和经度Projection。我已经检查了官方网站,但我不知道如何实施它。

总结一下,如何TextView通过不拖放标记而是平移地图来提供动态地址更改?

这也是我的代码给你看看我如何在拖动标记结束时处理拖动方法它显示当前地址参考此代码

@Override
public void onMarkerDragEnd(Marker marker) {
    LatLng position=marker.getPosition();

    String filterAddress = "";
    Geocoder geoCoder = new Geocoder(
            getBaseContext(), Locale.getDefault());
    try {
        List<Address> addresses = geoCoder.getFromLocation(
                position.latitude, 
                position.longitude, 1);

        if (addresses.size() > 0) {
            for (int index = 0; 
            index < addresses.get(0).getMaxAddressLineIndex(); index++)
                filterAddress += addresses.get(0).getAddressLine(index) + " ";
        }
    }catch (IOException ex) {        
        ex.printStackTrace();
    }catch (Exception e2) {
        // TODO: handle exception

        e2.printStackTrace();
    }


    TextView myTextView = (TextView) findViewById(R.id.test);
    myTextView.setText("Address " + filterAddress);




    Log.d(getClass().getSimpleName(), String.format("Dragged to %f:%f",
            position.latitude,
            position.longitude));
}

这里

4

1 回答 1

0

一旦你按照我提供的网址

http://maps.google.com/maps/api/geocode/json?address=mumbai&sensor=false

它以 json 格式返回数据,地址为 lat/lng。

public static void getLatLongFromAddress(String youraddress) {
    String uri = "http://maps.google.com/maps/api/geocode/json?address=" +
                  youraddress + "&sensor=false"
    HttpGet httpGet = new HttpGet(uri);
    HttpClient client = new DefaultHttpClient();
    HttpResponse response;
    StringBuilder stringBuilder = new StringBuilder();

    try {
        response = client.execute(httpGet);
        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        int b;
        while ((b = stream.read()) != -1) {
            stringBuilder.append((char) b);
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject = new JSONObject(stringBuilder.toString());

        lng = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
            .getJSONObject("geometry").getJSONObject("location")
            .getDouble("lng");

        lat = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
            .getJSONObject("geometry").getJSONObject("location")
            .getDouble("lat");

        Log.d("latitude", lat);
        Log.d("longitude", lng);
    } catch (JSONException e) {
        e.printStackTrace();
    }

}
于 2013-10-16T15:28:52.943 回答