如何从ArrayList中获取多个数据并将其显示在谷歌地图android代码段中?

如何从ArrayList中获取多个数据并将其显示在谷歌地图android代码段中?,android,google-maps,Android,Google Maps,我正在做一个GoogleMap项目,我必须从数组列表(从服务器检索)中获取数据(标题和代码段描述),并在标题和代码段中动态显示它。由于代码段中的描述很长,因此不会显示整个描述。下面是我的代码 当我点击标记时,我可以得到一个标题和一个片段。我需要的是,代码片段应该显示来自服务器的冗长描述。目前的情况是,有一个标题行和一个代码段行。描述在代码段中显示了一半。如果我不清楚,请告诉我。我们需要解决这个问题 @SuppressLint("NewApi") public class GoogleActivi

我正在做一个GoogleMap项目,我必须从数组列表(从服务器检索)中获取数据(标题和代码段描述),并在标题和代码段中动态显示它。由于代码段中的描述很长,因此不会显示整个描述。下面是我的代码

当我点击标记时,我可以得到一个标题和一个片段。我需要的是,代码片段应该显示来自服务器的冗长描述。目前的情况是,有一个标题行和一个代码段行。描述在代码段中显示了一半。如果我不清楚,请告诉我。我们需要解决这个问题

@SuppressLint("NewApi")
public class GoogleActivity extends FragmentActivity implements LocationListener {

    private LocationManager locationManager;
    private static final long MIN_TIME = 700;
    private static final float MIN_DISTANCE = 800;

    private Location mLocation;

    // Google Map
    private GoogleMap googleMap;
    LatLng myPosition;

    // All static variables
    static final String URL = "http://webersspot.accountsupport.com/gmaptrial/onedb/phpsqlajax_genxml.php";
    // XML node keys

    static final String KEY_PID = "pro"; // parent node
    static final String KEY_NAME = "Name";
    static final String KEY_DESCRIPTION = "Description";
    static final String KEY_LAT = "Latitude";
    static final String KEY_LONG = "Longitude";

    ArrayList<HashMap<String, String>> storeMapData = new ArrayList<HashMap<String, String>>();
    private ShareActionProvider mShareActionProvider;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //open the map
        openTheMap();


        /*

     // Get Location Manager and check for GPS & Network location services
        LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
        if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
              !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
          // Build the alert dialog
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle("Location Services Not Active");
          builder.setMessage("Please enable Location Services and GPS");
          builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialogInterface, int i) {
            // Show location settings when the user acknowledges the alert dialog
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
            }
          });
          Dialog alertDialog = builder.create();
          alertDialog.setCanceledOnTouchOutside(false);
          alertDialog.show();
        }
         */


        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME, MIN_DISTANCE, this); //You can also use LocationManager.GPS_PROVIDER and LocationManager.PASSIVE_PROVIDER        


        new LongOperation().execute("");
        new MapOperation().execute(googleMap);


    }



    /* open the map */
    private void openTheMap() {
        try {
            if(googleMap == null) {

                SupportMapFragment mapFragment =
                        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

                googleMap = mapFragment.getMap();
                googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);  // Hybrid for satellite with place name
                googleMap.setMyLocationEnabled(true);  // enable user location button.
                googleMap.setInfoWindowAdapter(null) ;
                googleMap.getUiSettings().setZoomControlsEnabled(true);
                googleMap.getUiSettings().setCompassEnabled(true);
                googleMap.getUiSettings().setMyLocationButtonEnabled(true);
                googleMap.getUiSettings().setAllGesturesEnabled(true);
                googleMap.setTrafficEnabled(true); // enable road 
                zoomMap();
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* zoom current location */
    private void zoomMap() {
        int zoomScale = 12;
        double currentLat = mLocation.getLatitude();
        double currentLon = mLocation.getLongitude();
        googleMap.moveCamera(CameraUpdateFactory
                .newLatLngZoom(new LatLng(currentLat, currentLon), zoomScale));



    }

    public List<HashMap<String, String>> prepareData(){

        ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
        //List<HashMap<String, String>>  menuItems = new ArrayList<HashMap<String, String>>();

        XmlParser parser = new XmlParser();
        String xml = parser.getXmlFromUrl(URL); // getting XML
        Document doc = parser.getDomElement(xml); // getting DOM element

        NodeList nl = doc.getElementsByTagName(KEY_PID);
        // looping through all item nodes <item>
        for (int i = 0; i < nl.getLength(); i++) {
            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);

            System.out.println("OOOOOOOOOOOOOOOOOOO  ::: "+e.getAttribute(KEY_NAME));
            // adding each child node to HashMap key => value

            map.put(KEY_NAME, e.getAttribute(KEY_NAME).toString());
            map.put(KEY_DESCRIPTION ,e.getAttribute(KEY_DESCRIPTION).toString());
            map.put(KEY_LAT, e.getAttribute(KEY_LAT).toString());
            map.put(KEY_LONG ,e.getAttribute(KEY_LONG).toString());


            // adding HashList to ArrayList
            menuItems.add(map);
            storeMapData = menuItems;



        }
        return menuItems;

    }

    public void onMapReady(final GoogleMap map) {       
        ArrayList<HashMap<String, String>> processData = storeMapData;



        System.out.println( "kjkasdc   "+processData);

        for (int i=0; i< processData.size(); i++){


            final double lat = Double.parseDouble(processData.get(i).get(KEY_LAT));
            System.out.println("MAP LAT :::::::::::::::::::::::::  "+lat);
            final double lon =  Double.parseDouble(processData.get(i).get(KEY_LONG));
            System.out.println("MAP LON :::::::::::::::::::::::::  "+lon);
            final String address = processData.get(i).get(KEY_DESCRIPTION);
            System.out.println("MAP ADDRESS :::::::::::::::::::::::::  "+address);
            final String name = processData.get(i).get(KEY_NAME);
            System.out.println("MAP ADDRESS :::::::::::::::::::::::::  "+name);




            runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    map.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title(name).snippet(address).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW)));



                }
            });

        }
    }



    @SuppressLint("NewApi")
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        /** Inflating the current activity's menu with res/menu/items.xml */
        getMenuInflater().inflate(R.menu.share_menu, menu);     

        mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_item_share).getActionProvider();

        /** Setting a share intent */
        mShareActionProvider.setShareIntent(getDefaultShareIntent());


        return super.onCreateOptionsMenu(menu);

    }    

    /** Returns a share intent */
    private Intent getDefaultShareIntent(){     
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");       
        intent.putExtra(Intent.EXTRA_SUBJECT,"Download");
        intent.putExtra(Intent.EXTRA_TEXT,"Download Hill Top Beauty Parlour App - Maroli from Google Play Store:  https://play.google.com/store/apps/details?id=beauty.parlour.maroli");        
        return intent;
    }


    private class LongOperation extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {         
            prepareData();      
            return "Executed";
        }
        @Override
        protected void onPostExecute(String result) {               
            System.out.println("Executed");
        }
        @Override
        protected void onPreExecute() {         
            System.out.println("Execution started");            
        }
        @Override
        protected void onProgressUpdate(Void... values) {

            System.out.println("     -- -- -- "+values);
        }
    }

    private class MapOperation extends AsyncTask<GoogleMap, Void, String> {
        @Override
        protected String doInBackground(GoogleMap... params) {    
            GoogleMap map = params[0];
            onMapReady(map);    
            return "Executed";
        }
        @Override
        protected void onPostExecute(String result) {               
            System.out.println(result);
        }
        @Override
        protected void onPreExecute() {         
            System.out.println("Execution started");            
        }
        @Override
        protected void onProgressUpdate(Void... values) {

            System.out.println("     -- -- -- "+values);
        }
    }

    class MyInfoWindowAdapter implements InfoWindowAdapter{

        private final View myContentsView;

        MyInfoWindowAdapter(){
            myContentsView = getLayoutInflater().inflate(R.layout.custom_info_contents, null);
        }

        @Override
        public View getInfoContents(Marker marker) {

            TextView tvTitle = ((TextView)myContentsView.findViewById(R.id.title));
            tvTitle.setText(marker.getTitle());


            TextView tvaddress = ((TextView)myContentsView.findViewById(R.id.snippet));
            tvaddress.setText(marker.getTitle());




            return myContentsView;
        }



        @Override
        public View getInfoWindow(Marker marker) {
            // TODO Auto-generated method stub


            return null;
        }
    }

    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
        googleMap.animateCamera(cameraUpdate);
        locationManager.removeUpdates(this);

    }


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

    }


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

    }


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

    }


}
@SuppressLint(“NewApi”)
公共类GoogleActivity扩展FragmentActivity实现LocationListener{
私人场所经理场所经理;
专用静态最终长最小时间=700;
专用静态最终浮动最小距离=800;
私人位置;
//谷歌地图
私人谷歌地图谷歌地图;
车床位置;
//所有静态变量
静态最终字符串URL=”http://webersspot.accountsupport.com/gmaptrial/onedb/phpsqlajax_genxml.php";
//XML节点密钥
静态最终字符串键\u PID=“pro”//父节点
静态最终字符串键\u NAME=“NAME”;
静态最终字符串键\u DESCRIPTION=“DESCRIPTION”;
静态最终字符串键\u LAT=“纬度”;
静态最终字符串键\u LONG=“经度”;
ArrayList storeMapData=新建ArrayList();
私有ShareActionProvider mShareActionProvider;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//打开地图
打开地图();
/*
//获取位置管理器并检查GPS和网络位置服务
LocationManager lm=(LocationManager)getSystemService(位置服务);
如果(!lm.isProviderEnabled)(LocationManager.GPS\U提供程序)||
!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
//构建警报对话框
AlertDialog.Builder=新建AlertDialog.Builder(此);
builder.setTitle(“位置服务未激活”);
builder.setMessage(“请启用定位服务和GPS”);
setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){
公共void onClick(DialogInterface,inti){
//当用户确认警报对话框时显示位置设置
意向意向=新意向(设置、动作、位置、来源、设置);
星触觉(意向);
}
});
Dialog alertDialog=builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
}
*/
locationManager=(locationManager)getSystemService(Context.LOCATION\u服务);
locationManager.RequestLocationUpdate(locationManager.NETWORK_提供程序,最小时间,最小距离,this);//您还可以使用locationManager.GPS_提供程序和locationManager.PASSIVE_提供程序
新建LongOperation()。执行(“”);
新建MapOperation().execute(谷歌地图);
}
/*打开地图*/
私有void openTheMap(){
试一试{
if(googleMap==null){
SupportMapFragment映射片段=
(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
googleMap=mapFragment.getMap();
googleMap.setMapType(googleMap.MAP_TYPE_HYBRID);//用于带有地名的卫星的HYBRID
setMyLocationEnabled(true);//启用用户位置按钮。
setInfoWindowAdapter(空);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.getUiSettings().setAllGesturesEnabled(true);
googleMap.setTrafficEnabled(true);//启用道路
zoomMap();
}
}捕获(NullPointerException e){
e、 printStackTrace();
}捕获(例外e){
e、 printStackTrace();
}
}
/*缩放当前位置*/
私有void zoomMap(){
int zoomScale=12;
double currentLat=mLocation.getLatitude();
double currentLon=mLocation.getLongitude();
googleMap.moveCamera(CameraUpdateFactory
.newLatLngZoom(newlatlng(currentLat,currentLon),zoomScale);
}
已编制的公共列表数据(){
ArrayList menuItems=新建ArrayList();
//List menuItems=new ArrayList();
XmlParser=新的XmlParser();
字符串xml=parser.getXmlFromUrl(URL);//获取xml
Document doc=parser.getDomeElement(xml);//获取DOM元素
NodeList nl=doc.getElementsByTagName(KEY_PID);
//循环通过所有项目节点
对于(int i=0;ivalue
map.put(KEY_NAME,e.getAttribute(KEY_NAME.toString());
map.put(KEY_DESCRIPTION,例如getAttribute(KEY_DESCRIPTION.toString());
map.put(KEY_LAT,e.getAttribute(KEY_LAT.toString());
map.put(KEY_LONG,e.getAttribute(KEY_LONG.toString());
//将哈希列表添加到ArrayList
menuItems.add(地图);
storeMapData=menuItems;
}
返回菜单项;
}
已准备好(谷歌地图最终版){
ArrayList processData=storeMapData;
系统