Created
June 8, 2015 17:55
-
-
Save yudanta/a25c8c9694e95e82538b to your computer and use it in GitHub Desktop.
DetailActivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package co.nuwira.nwrandroiddev; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.support.v7.app.ActionBarActivity; | |
import android.widget.TextView; | |
import com.google.android.gms.maps.CameraUpdateFactory; | |
import com.google.android.gms.maps.GoogleMap; | |
import com.google.android.gms.maps.SupportMapFragment; | |
import com.google.android.gms.maps.model.LatLng; | |
import com.google.android.gms.maps.model.Marker; | |
import com.google.android.gms.maps.model.MarkerOptions; | |
/** | |
* Created by Amanda on 6/9/15. | |
*/ | |
public class DetailActivity extends ActionBarActivity { | |
GoogleMap map; | |
Marker mMarker; | |
TextView shelterName; | |
TextView shelterDesc; | |
TextView latLon; | |
Shelter shelterObj = null; | |
@Override | |
public void onCreate(Bundle savedInstanceState){ | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.detail_layout); | |
shelterName = (TextView) findViewById(R.id.shelterName); | |
shelterDesc = (TextView) findViewById(R.id.shelterDesc); | |
latLon = (TextView) findViewById(R.id.latLon); | |
//get extras | |
try { | |
Bundle extras = getIntent().getExtras(); | |
if (extras != null){ | |
if (extras.getInt("id")!= 0){ | |
shelterObj = new Shelter(); | |
shelterObj.setIdShelter(extras.getInt("id")); | |
shelterObj.setName(extras.getString("name")); | |
shelterObj.setDescription(extras.getString("description")); | |
shelterObj.setLatitude(extras.getDouble("latitude")); | |
shelterObj.setLongitude(extras.getDouble("longitude")); | |
} | |
} | |
}catch (Exception e){e.printStackTrace();} | |
shelterName.setText(shelterObj.getName()); | |
shelterDesc.setText(shelterObj.getDescription()); | |
latLon.setText(Double.toString(shelterObj.getLatitude()) + " - " + Double.toString(shelterObj.getLongitude())); | |
//set map | |
if (map == null) | |
{ | |
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); | |
} | |
//if map is not null | |
if (map != null) { | |
map.setMapType(GoogleMap.MAP_TYPE_NORMAL); | |
if (shelterObj != null){ | |
//add marker | |
map.clear(); | |
mMarker = map.addMarker(new MarkerOptions() | |
.position(new LatLng(shelterObj.getLatitude(), shelterObj.getLongitude())) | |
.title(shelterObj.getName())); | |
//move map camera | |
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(shelterObj.getLatitude(), shelterObj.getLongitude()), 15)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment