2

MapviewGoogleと aListViewを 1 つに合わせようとしていますactivityMapviewが上側2/3、リストが下側の 1/3 になります (縦長) 。

このようにして、縦向きと仮定します:http://i.stack.imgur.com/IoGjr.png

MapViewと の両方ListViewが同じJSON情報を受け取り、 を取得しonCreate()ます。すでに画面に収まり、MapView位置2/3を取得するListViewデータを取得できました。しかし、私が乗った場所listViewもピンセットで表示さmaplocationれるようにしたいのですが、それを表示する方法を教えてもらえますmap?

ここに私のコードがあります:

// リクエストを非公開にするための url static String url = ""; // ここで URL を渡します

// JSON Node names
    private static final String TAG_LOCATION = "location";
    private static final String TAG_LOCATION1= "location";
    private static final String TAG_LOCATION_ID = "LocationID";
    private static final String TAG_NAME = "Name";
    private static final String TAG_PHONE = "Phone";
    private static final String TAG_FORMATTED_PHONE = "FormattedPhone";
    private static final String TAG_ADDRESS = "Address";
    private static final String TAG_CROSS_STREET = "CrossStreet";
    private static final String TAG_LAT = "Lat";
    private static final String TAG_LNG = "Lng";
    private static final String TAG_DISTANCE= "Distance";
    private static final String TAG_POSTAL_CODE = "PostalCode";
    private static final String TAG_CITY = "City";
    private static final String TAG_STATE = "State";
    private static final String TAG_COUNTRY= "Country";

 // contacts JSONArray
    JSONArray location = null;
    JSONObject location1=null;

    ListView locationList;
    private MapView mapView;
    LocationManager lm;
    LocationListener locationListener;
    MapController mapController;

    private ListAdapter adapter;

    private static final double lat = 22.722990;
    private static final double lng = 75.857849;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_map);

        locationList=( ListView)findViewById(R.id.list_Surroundings);



        // Hashmap for ListView
        ArrayList<HashMap<String, String>> locationOfList = new ArrayList<HashMap<String, String>>();

        adapter = new SimpleAdapter(this, locationOfList,
                R.layout.list_item1,
                new String[] { TAG_NAME }, new int[] {
                        R.id.name});

        locationList.setAdapter(adapter);

     // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();

     // getting JSON string from URL
        JSONObject json = jParser.getJSONFromUrl(url);

        try {
         // Getting Array of Category
        location=json.getJSONArray(TAG_LOCATION);

        //looping through all categories
        for(int i = 0; i < location.length(); i++){
            JSONObject c = location.getJSONObject(i);
            JSONObject c1=c.getJSONObject(TAG_LOCATION1);

            // Storing each json item in variable
                String LocationID = c1.getString(TAG_LOCATION_ID);
                String Name = c1.getString(TAG_NAME);
                String Phone = c1.getString(TAG_PHONE);
                String FormattedPhone = c1.getString(TAG_FORMATTED_PHONE);
                String Address = c1.getString(TAG_ADDRESS);
                String CrossStreet = c1.getString(TAG_CROSS_STREET);
                String Lat = c1.getString(TAG_LAT);
                String Lng = c1.getString(TAG_LNG);
                String Distance = c1.getString(TAG_DISTANCE);
                String PostalCode = c1.getString(TAG_POSTAL_CODE);
                String City = c1.getString(TAG_CITY);
                String State = c1.getString(TAG_STATE);
                String Country = c1.getString(TAG_COUNTRY);

            // creating new HashMap
               HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value
               map.put(TAG_LOCATION_ID, LocationID);
               map.put(TAG_NAME, Name);
               map.put(TAG_PHONE, Phone);
               map.put(TAG_FORMATTED_PHONE, FormattedPhone);
               map.put(TAG_ADDRESS, Address);
               map.put(TAG_CROSS_STREET, CrossStreet);
               map.put(TAG_LAT, Lat);
               map.put(TAG_LNG, Lng);
               map.put(TAG_DISTANCE, Distance); 
               map.put(TAG_POSTAL_CODE, PostalCode);
               map.put(TAG_CITY, City);
               map.put(TAG_STATE, State);
               map.put(TAG_COUNTRY, Country);

               // adding HashList to ArrayList
               locationOfList.add(map);
        }
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }

                mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);

        List mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(
                R.drawable.map_pin_red);
        CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(
                drawable, this);

        GeoPoint point = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
        OverlayItem overlayitem = new OverlayItem(point, "Hello",
                "I'm in Athens, Greece!");

        itemizedOverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedOverlay);

        mapController = mapView.getController();

        mapController.animateTo(point);
        mapController.setZoom(10);

        lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
        locationListener= new MylocationListener();
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    }

    public class MylocationListener implements LocationListener{


        @Override
        public void onLocationChanged(Location loc) {
            // TODO Auto-generated method stub
            if(loc!=null){
                Toast.makeText(getBaseContext(), "Location Changed : Lat:" +loc.getLatitude() + "Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show();
            }
            GeoPoint point = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
            mapController.animateTo(point);
            mapController.setZoom(10);
        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

}
4

0 に答える 0