地図を表示させるぞ
…と思ってもそもそやっていたのだけれど、途中のコード残しとくの忘れた。とりあえず最終的なやつ。
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } /** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; LatLng fuji = new LatLng(35.362859,138.730883); BitmapDescriptor iconSanta = BitmapDescriptorFactory.fromResource(R.drawable.christmas_santa_sori_s); MarkerOptions option = new MarkerOptions(); option.icon(iconSanta).position(fuji); mMap.addMarker(option); mMap.moveCamera(CameraUpdateFactory.newLatLng(fuji)); } }
めちゃめちゃ簡単なんだなぁ。ついでにマーカーの画像も変えてみた。
参考
https://developers.google.com/maps/documentation/android-sdk/start
https://developers.google.com/android/reference/com/google/android/gms/maps/model/MarkerOptions