Created
October 15, 2016 11:54
-
-
Save mikkipastel/ce4fea364e9aaf56d8e6f375d2afecc0 to your computer and use it in GitHub Desktop.
tmp for google map
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".BusMapActivity"> | |
<!-- xmlns:map="http://schemas.android.com/apk/res-auto" --> | |
<!--<fragment xmlns:android="http://schemas.android.com/apk/res/android" | |
android:name="com.google.android.gms.maps.MapFragment" | |
android:id="@+id/map" | |
android:layout_height="match_parent" | |
android:layout_width="match_parent"/> --> | |
<!--<fragment xmlns:android="http://schemas.android.com/apk/res/android" | |
android:name="com.google.android.gms.maps.MapFragment" | |
android:id="@+id/map" | |
android:layout_height="match_parent" | |
android:layout_width="match_parent" | |
map:cameraTargetLat="13.651746" | |
map:cameraTargetLng="100.494872" | |
map:cameraBearing="112.5" | |
map:cameraTilt="65" | |
map:cameraZoom="17"/> --> | |
<FrameLayout | |
android:id="@+id/contentContainer" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</LinearLayout> |
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
import android.Manifest; | |
import android.app.FragmentTransaction; | |
import android.content.Context; | |
import android.content.pm.PackageManager; | |
import android.location.Location; | |
import android.location.LocationListener; | |
import android.location.LocationManager; | |
import android.os.Build; | |
import android.os.Bundle; | |
import android.support.v4.app.ActivityCompat; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v7.app.AppCompatActivity; | |
import com.google.android.gms.common.api.GoogleApiClient; | |
import com.google.android.gms.maps.CameraUpdateFactory; | |
import com.google.android.gms.maps.GoogleMap; | |
import com.google.android.gms.maps.MapFragment; | |
import com.google.android.gms.maps.OnMapReadyCallback; | |
import com.google.android.gms.maps.model.BitmapDescriptorFactory; | |
import com.google.android.gms.maps.model.CameraPosition; | |
import com.google.android.gms.maps.model.LatLng; | |
import com.google.android.gms.maps.model.Marker; | |
import com.google.android.gms.maps.model.MarkerOptions; | |
public class BusMapActivity extends AppCompatActivity implements OnMapReadyCallback { | |
GoogleMap mMap; | |
boolean mapReady = false; | |
double lat, lng; | |
Marker mMarker; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_map); | |
//MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); | |
//mapFragment.getMapAsync(this); | |
//add map fragment | |
MapFragment mapFragment = MapFragment.newInstance(); | |
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); | |
fragmentTransaction.add(R.id.contentContainer, mapFragment); | |
fragmentTransaction.commit(); | |
mapFragment.getMapAsync(this); | |
} | |
@Override | |
public void onMapReady(GoogleMap googleMap) { | |
//Do something with google map | |
mapReady = true; | |
mMap = googleMap; | |
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); | |
//test for show current location | |
LatLng lat = new LatLng(13.651746, 100.494872); | |
CameraPosition cameraPosition = new CameraPosition.Builder() | |
.target(lat).bearing(112.5f).zoom(17).build(); | |
//add marker | |
MarkerOptions marker1 = new MarkerOptions().position(lat).title("You are here."); | |
marker1.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE)); | |
mMap.addMarker(marker1); | |
//commit | |
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); | |
} | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:gravity="center_vertical" | |
android:background="@color/background" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment