我需要帮助。如何在另一个类的坐标中显示地图中的标记?
这里我在同一个班级中有arraylist和对话提醒
AlertDialog.Builder mAlert = new AlertDialog.Builder(HotelBintang.this);
view = getLayoutInflater().inflate(R.layout.alert_background, null);
ImageView Content_img = (ImageView)view.findViewById(R.id.imageView1);
TextView Content_txt1 = (TextView)view.findViewById(R.id.textView1);
Content_img.setImageResource(item_detail.get(position).getImageNumber());
Content_txt1.setText(item_detail.get(position).getName());
mAlert.setTitle(item_detail.get(position).getName()).
setView(view).
setPositiveButton("Get Coordinate", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Intent intent = new Intent(Hotel.this, MapsActivity.class);
intent.putExtra("lon", item_detail.get(position).lon);
intent.putExtra("lat", item_detail.get(position).lat);
HotelBintang.this.startActivity(intent);
}
}).create().show();
private ArrayList<ItemDetail> GetSearchResult()
{
ArrayList<ItemDetail> result = new ArrayList<ItemDetail>();
ItemDetail item_detail = new ItemDetail();
item_detail.setName("Taman Sari");
item_detail.setImageNumber(images[0]);
item_detail.ALoc(-6.917222222, 106.9758333);
result.add(item_detail);
item_detail = new ItemDetail();
item_detail.setName("Taman Sari");
item_detail.setImageNumber(images[0]);
item_detail.ALoc(-6.917222222, 106.9758333);
result.add(item_detail);
return result;
}
我想点击“获取坐标”按钮,在地图中显示标记。
这是我的MapsActivity类:
public class MapsAcivity extends FragmentActivity {
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
String lon = getIntent().getExtras().getString("lon");
String lat = getIntent().getExtras().getString("lat");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.peta_layout);
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
LatLng sukabumi = new LatLng(-7.149949,106.799254);
MarkerOptions markerSukabumi = new MarkerOptions();
markerSukabumi.position(sukabumi);
markerSukabumi.title("Sukabumi");
markerSukabumi.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
myMap.addMarker(markerSukabumi);
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
myMap.getUiSettings().setCompassEnabled(true);
myMap.getUiSettings().setZoomControlsEnabled(true);
myMap.getUiSettings().setMyLocationButtonEnabled(true);
myMap.setMyLocationEnabled(true);
myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(sukabumi, 9));
myMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
try {
StringBuilder urlString = new StringBuilder();
String daddr = (String.valueOf(arg0.getPosition().latitude)+","+String.valueOf(arg0.getPosition().longitude));
urlString.append("http://maps.google.com/maps?f=d&hl=en");
urlString.append("&saddr="+String.valueOf(myMap.getMyLocation().getLatitude())+","+String.valueOf(myMap.getMyLocation().getLongitude()));
urlString.append("&daddr="+daddr);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString.toString()));
startActivity(i);
} catch (Exception ee) {
Toast.makeText(getApplicationContext(), "Please Turn On your GPS.", Toast.LENGTH_LONG).show();
}
return false;
}
});
请帮帮我。
答案 0 :(得分:1)
将String lon = getIntent().getExtras().getString("lon");
和String lat = getIntent().getExtras().getString("lat");
移至您的onCreate()
方法,并在创建市场时使用Double.parseDouble(String s)。像这样:LatLng sukabumi = new LatLng(Double.parseDouble(lat),Double.parseDouble(lon));