Android的检索上mapsv2当前位置动态 [英] android Retrieving current position on mapsv2 dynamically

查看:189
本文介绍了Android的检索上mapsv2当前位置动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我有几个与这个问题相关的话题却依然没有得到逻辑之外没有人提供了一个明确的解决方案。无论如何,我会试着问再次明确,并提供截图(来自示例应用程序),希望它会做的魔力。

Well , I have couple of topic related with this issue but still did not got the logic besides nobody provides a clear solution. Anyway, I will try to ask it again clearly and provide a screenshot (from a sample app) hope it would do the magic.

正如你可以看到下面有关于谷歌地图自定义的标记,我可以通过添加的ImageView 实现它向我的方案。在以上的地图有一个的TextView 。在有地址变更时,动态在地图上标记位置变化。但我们不能拖&放;下降的标志是固定在中央,而不是拖动。我们所做的只是平移地图。当我们停止平移的标记显示的地方在地图上,并很快显示为在的TextView 的地址。

As you can see below there is a custom marker on google maps, I can implement it to my scenario by adding an Imageview. On above of the maps there is a TextView. In there address change dynamically when the markers position change on the maps. BUT we are not drag&drop the marker it is fixed to center and not draggable. What we are doing is just panning the map. When we stop panning the marker is show somewhere on the map and it quickly display as an address in a Textview.

我可以通过处理 onMarkerDragEnd()更改地址,但是这是一个不同的场景。也没有GPS连接,我想它是使用投影类转换的观点 screenPosition 的经度和纬度。我检查的官方网站,但我想不出的想法如何实现它。

I can change the address by handling onMarkerDragEnd() but this is a different scenario. Also there is no GPS connection I guess it is converting views screenPosition to latitude and longitude using Projection class. I've checked the official site it but I couldnt get the idea how to implement it.

也是如此总结,我怎么可以不提供在的TextView 动态地址改变拖放放大器;下降的标志,但平移地图

So too sum up, How can I provide a dynamic address change in a TextView by not drag&drop a marker but panning the map?

也在这里是我的code对你也看到我是如何处理拖动的方法拖动标记结束它显示在参考本code

also here is my code for you too see how I handle the drag method when dragging the marker ends it displays the current address in refer to this code

@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));
}

推荐答案

一旦你遵循哪个我提供的网址

once you follow the url which i am providing

的http://地图。 google.com/maps/api/geo$c$c/json?address=mumbai&sensor=false

这与地址的纬度/经度JSON格式返回数据。

which returns data in json format with lat/lng of address.

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();
    }

}

这篇关于Android的检索上mapsv2当前位置动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆