Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中,是否可以创建字符串和latlng数组?_Android_Arrays - Fatal编程技术网

在Android中,是否可以创建字符串和latlng数组?

在Android中,是否可以创建字符串和latlng数组?,android,arrays,Android,Arrays,我试图创建最多6行的地名和地名数组,然后使用意图将其发送到用户可以选择名称的map类。该名称仍需绑定到板条上,以便地图可以居中并缩放到该名称 我在下面添加了经过编辑的代码。我有一个混合的putExtra和putParcelable,因为我正在尝试任何东西来获得一个工作原型。希望这有点道理 发送类地理代码如下所示: private void geocodeLocation(String gPlace) { Geocoder gGeocoder = new Geocoder(this

我试图创建最多6行的地名和地名数组,然后使用意图将其发送到用户可以选择名称的map类。该名称仍需绑定到板条上,以便地图可以居中并缩放到该名称

我在下面添加了经过编辑的代码。我有一个混合的putExtra和putParcelable,因为我正在尝试任何东西来获得一个工作原型。希望这有点道理

发送类地理代码如下所示:

private void geocodeLocation(String gPlace) {
        Geocoder gGeocoder = new Geocoder(this, Locale.getDefault());
        try{
            List<Address> results = null;
            if(Geocoder.isPresent()){
                results = gGeocoder.getFromLocationName(gPlace, numberOptions);
            } else {
                return;
            }
            Iterator<Address> locations = results.iterator();
            String country;
            int opCount = 0; 
            while(locations.hasNext()){
                Address location = locations.next();
                raw += location+"\n";
                strAddressOutput[opCount] = location.getAddressLine(0) + ", " + location.getAddressLine(1) + country  + "\n";
                strLatOutput[opCount] = location.getLatitude();
                strLongOutput[opCount] = location.getLongitude();
                gLatLng = new LatLng(location.getLatitude(),location.getLongitude());
                strLatLng[opCount] = gLatLng;
                opCount ++;
            }

            for(int i = 0; i<opCount; i++){
            }
        } catch (IOException e){
        }
接收类别如下:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.main_map);

            MapFragment mapFrag = (MapFragment) getFragmentManager().findFragmentById(R.id.map);

            if (savedInstanceState == null) {
                needsInit = true;
            }
            mapFrag.getMapAsync(this);  

        mPlace = (EditText) findViewById(R.id.txAddress);
        mAddressList = (Spinner) findViewById(R.id.spinAddressList);

        mPlace.setText(getIntent().getStringExtra(Constants.PLACE));

        String[] recAddressAA = getIntent().getStringArrayExtra(Constants.RETURNEDADDRESS); // NULLS from Geocoder?

        recAddressOutput = recAddressAA;

        String testAddressOutput = Arrays.toString(recAddressAA);

        Bundle bundleMapCentre = getIntent().getParcelableExtra("bundle");
        mMapCentre = bundleMapCentre.getParcelable (Constants.MAPCENTRE);

        Bundle bundleLatLng = getIntent().getParcelableExtra("bundle");
        LatLng[] mLatLng = bundleLatLng.getParcelableArrayList(Constants.LATLNGS); 

        mAdapter = new ArrayAdapter<String>(MainMap.this, android.R.layout.simple_spinner_item, recAddressOutput);  
        mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mAddressList.setAdapter(mAdapter); 

        });
    }

行“LatLng[]mLatLng=bundleLatLng.getParcelableArrayListConstants.LATLNGS;”错误,但我已经后退一步,看看这是否是一种可行的方法

Intent允许您传递整数、双精度、字符串等。但是如果您想要传递自定义对象,则必须创建实现Parcoable的自定义对象。您可以看到一些关于如何做到这一点的信息

LatLng可以发送到intent中,因为它已经实现了parseable抱歉,应该更清楚。我相信他必须创建一个自定义对象来保存一个LatLng和一个地名。他可以使用intent.putParcelableArrayListExtraHe通过intent传递这些对象的ArrayList。他可以使用2个ArrayList来完成这项工作。一个ArrayList和一个ArrayList。他们会维持秩序的。嗨,魔术师,谢谢你的意见。我应该如何获取并放置2个ArrayList?关于名称绑定到latlng的部分使我成为hashmap的一部分您可以接收值并在map类中使用它们构建hashmap。一个问题:您事先有LatLongitus值吗?名字呢?如果是这样的话,您可以将它们存储在sqlite中,然后使用intent extras传递特定位置的id,而不是传递整个对象;我读过一些,似乎集合可以通过intent传递,这样您就可以拥有hashmap并在intent中传递它。错误是“不兼容的类型:Required com.google.android.gms.maps.model.LatLng[]find java.util.ArrayList”
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.main_map);

            MapFragment mapFrag = (MapFragment) getFragmentManager().findFragmentById(R.id.map);

            if (savedInstanceState == null) {
                needsInit = true;
            }
            mapFrag.getMapAsync(this);  

        mPlace = (EditText) findViewById(R.id.txAddress);
        mAddressList = (Spinner) findViewById(R.id.spinAddressList);

        mPlace.setText(getIntent().getStringExtra(Constants.PLACE));

        String[] recAddressAA = getIntent().getStringArrayExtra(Constants.RETURNEDADDRESS); // NULLS from Geocoder?

        recAddressOutput = recAddressAA;

        String testAddressOutput = Arrays.toString(recAddressAA);

        Bundle bundleMapCentre = getIntent().getParcelableExtra("bundle");
        mMapCentre = bundleMapCentre.getParcelable (Constants.MAPCENTRE);

        Bundle bundleLatLng = getIntent().getParcelableExtra("bundle");
        LatLng[] mLatLng = bundleLatLng.getParcelableArrayList(Constants.LATLNGS); 

        mAdapter = new ArrayAdapter<String>(MainMap.this, android.R.layout.simple_spinner_item, recAddressOutput);  
        mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mAddressList.setAdapter(mAdapter); 

        });
    }