-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignalMaps.java
69 lines (59 loc) · 2.76 KB
/
SignalMaps.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package edu.nctu.wirelab.testsignalv1;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class SignalMaps extends FragmentActivity implements OnMapReadyCallback {
private final String TagName = new String("SignalMaps");
private GoogleMap mMap;
private MarkerOptions UserMark;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signal_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;
// 建立位置的座標物件
if( LocationUpdater.userlocation!=null ) {
Log.d(TagName, "Lat:" + LocationUpdater.userlocation.getLatitude() + " Lnt:" + LocationUpdater.userlocation.getLongitude());
LatLng place = new LatLng(LocationUpdater.userlocation.getLatitude(), LocationUpdater.userlocation.getLongitude());
// 移動地圖
moveMap(place);
UserMark = null;
UserMark = new MarkerOptions().position(place).title("I'm here");
mMap.addMarker(UserMark);
}
}
// 移動地圖到參數指定的位置
private void moveMap(LatLng place) {
// 建立地圖攝影機的位置物件
CameraPosition cameraPosition =
new CameraPosition.Builder()
.target(place)
.zoom(17)
.build();
// 使用動畫的效果移動地圖
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}