Android 如何在应用程序中的特定位置启动“地图”活动?

Android 如何在应用程序中的特定位置启动“地图”活动?,android,google-maps,Android,Google Maps,因此,我有一个位置列表(在ListFragment中)及其相应的坐标,我想在按下其中一个位置时启动一个新的映射活动 public void onListItemClick(ListView l, View v, int position, long id) { Toast.makeText(getActivity(), "Item: " + locations[position], Toast.LENGTH_SHORT).show(); Intent eventActivity

因此,我有一个位置列表(在ListFragment中)及其相应的坐标,我想在按下其中一个位置时启动一个新的映射活动

public void onListItemClick(ListView l, View v, int position, long id) {
    Toast.makeText(getActivity(), "Item: " + locations[position], Toast.LENGTH_SHORT).show();
    Intent eventActivity = new Intent(getContext(), MapsActivity.class);
    startActivity(eventActivity);
}
目前我有它,所以当点击其中一个项目时,它会显示位置的名称,然后在应用程序中打开一个指向(0,0)的地图。如何将地图打开到与位置(我拥有)对应的坐标

多亏了Ajeet Choudhary。解决了的。解决方案如下。

MapFragment.java

public class MapFragment extends ListFragment{

...

LatLng[] coordinates = new LatLng[] {
        new LatLng(..., ...),
        new LatLng(..., ...),
        new LatLng(..., ...),
        ...
};

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ArrayAdapter<String> adapter = new MapAdapter(getActivity(), locations);
    setListAdapter(adapter);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Toast.makeText(getActivity(), "Item: " + locations[position], Toast.LENGTH_SHORT).show();
    Intent eventActivity = new Intent(getContext(), MapsActivity.class);
    eventActivity.putExtra("latlng", coordinates[position]);
    startActivity(eventActivity);
}
}

由于Latlng已经实现了PARTABLE类,所以将其放入intent并发送到您的Map活动中,从getIntent().getParcableExtra(“您的密钥”)获取Latlng,然后将有方法onMapReady(GoogleMap GoogleMap)(如果您已经实现了Map)将您的Latlng添加到Map中,请参阅以获取帮助。

您是否仅拥有该特定位置或地址的标签?两者都有。我有一份地点名称、实际地址和地址的清单。位置名称和物理地址显示在列表中。什么是主活动?若它是你们的类,那个么在问题中添加相应的代码。你们是说MapsActivity?这只是一个默认的GoogleMaps类,我从示例应用程序中获得,在代码LatLng location=new LatLng(,);你在那里吃拿铁吗??
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker and move the camera.
    LatLng location = getIntent().getExtras().getParcelable("latlng");
    mMap.addMarker(new MarkerOptions().position(location).title("Marker"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(location));
}
}