2013-10-16 22 views
0

那麼現在的位置,我有幾個與此問題相關的話題,但仍然沒有得到邏輯之外沒有人提供了一個明確的解決方案。無論如何,我會試着再次清楚地詢問它,並提供一個屏幕截圖(來自示例應用程序),希望它能做到這一點。Android的檢索上mapsv2動態

正如你可以看到下面有關於谷歌地圖自定義標記,我可以通過添加Imageview落實我的方案。在地圖上方有一個TextView。當地圖上的標記位置發生變化時,地址會動態變化。但我們不是拖動&將它固定到中心而不是可拖動的標記。我們正在做的只是平移地圖。當我們停止平移的標誌是什麼地方在地圖上顯示,並很快顯示爲在Textview的地址。

我可以通過處理onMarkerDragEnd()更改地址,但是這是一個不同的場景。也沒有GPS連接我想這是使用Projection類經度轉換的觀點screenPosition緯度和。我已經檢查過官方網站,但我不知道如何實現它。

太總結,如何通過不拖動來提供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)); 
} 

Here

回答

0

一旦你按照對此我提供

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

其重新鏈接以地址的經度/緯度轉換json格式的數據。

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

} 
+0

我在哪裏可以調用此方法? onCreate還是別的什麼地方?另外,lat和lng必須是全局變量,否則不會導致eclipse會說他們不會解析爲變量。謝謝 – regeme