How to show all locations on Map, i have successfully shown single location whenever user do tap on any of the list item, but now i have to show all locations on map using click on button
this is how my JSON look like:
{
"search": [
{
"country": "India",
"location": [
{
"title": "New Delhi",
"hotel": [
{
"name": "Hotel 5 Star",
"lat": 28.6413852,
"lon": 77.1211905,
"thumb": "UN_HQ.jpg"
},
{
"name": "Hotel Premium",
"lat": 28.6206446,
"lon": 77.0885432,
"thumb": "Avery_Fisher_Hall.jpg"
}
]
},
{
"title": "Bangalore",
"hotel": [
{
"name": "Hotel Comfort",
"lat": 12.97159870,
"lon": 77.59456269,
"thumb": "Carnegie_Hall.jpg"
}
]
}
]
},
{
"country": "USA",
"location": [
{
"title": "California",
"hotel": [
{
"name": "Hotel Zone",
"lat": 36.7782610,
"lon": -119.4179323,
"thumb": "UN_HQ.jpg"
}
]
}
]
}
]
}
HotelActivity.java:-
public class HotelActivity extends Activity implements OnItemClickListener {
ListView listview = null;
private ArrayList<Location> arrayListLocation;
private int index;
private Location location;
private ArrayList<Hotel> arrayListHotel;
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView) findViewById(R.id.listview);
Button btn = (Button) findViewById(R.id.button1);
Intent in = getIntent();
Bundle bundle = in.getBundleExtra("bundle");
arrayListLocation = (ArrayList<Location>) bundle.getSerializable("data");
index = bundle.getInt("index");
location = arrayListLocation.get(index);
arrayListHotel = location.getHotels();
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(HotelActivity.this, AllMapActivity.class);
startActivity(intent);
}
});
listview.setAdapter(new ThirdListViewAdapter(HotelActivity.this, arrayListHotel));
listview.setOnItemClickListener(this);
}
AllMapActivity.java:-
public class AllMapActivity extends Activity implements
OnInfoWindowClickListener {
private static final String STATE_NAV="nav";
private GoogleMap map=null;
private HashMap<String, Uri> images=new HashMap<String, Uri>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
MapFragment mapFrag=
(MapFragment)getFragmentManager().findFragmentById(R.id.map);
map=mapFrag.getMap();
if (savedInstanceState == null) {
CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(""),
Double.parseDouble("")));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
map.moveCamera(center);
map.animateCamera(zoom);
}
addMarker(map, Double.parseDouble(""), Double.parseDouble(""),
"", "snippet", "");
map.setInfoWindowAdapter(new PopupAdapter(this,
getLayoutInflater(),
images));
map.setOnInfoWindowClickListener(this);
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt(STATE_NAV,
getActionBar().getSelectedNavigationIndex());
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
getActionBar().setSelectedNavigationItem(savedInstanceState.getInt(STATE_NAV));
}
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(this, marker.getTitle(), Toast.LENGTH_LONG).show();
}
private void addMarker(GoogleMap map, double lat, double lon,
String title, String snippet, String image) {
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(lat, lon))
.title(title)
.snippet(snippet));
}
}
}