SlideShare a Scribd company logo
1 of 35
Download to read offline
警廣地圖APP開發
與 踩到的n個坑
(android google map 程式設計
一定要知道的事)
Mark Chiu
Markchiu.tw@gmail.com
2018.8.23.TaipeiTaiwan.
App feature
and ui
introduction
台灣車禍發生
率超越美日韓
 台灣車禍106年
 肇事率(1.4件/百輛)
 死亡率(0.7人/萬輛)
 受傷率(1.8人/百輛)
 每5小時又9分鐘
 台灣就有1人死於交通事故
Opendata挖礦
 如果我跟你說:
 我知道一個寶藏:那是一個充滿黃金的地方….
 You pay your time, you got money.
 Open dateTaiwan .國人專屬.
 還有: 中國,美加.英法俄 印度 日韓 ,南美, 中東
 台灣政府的行政效率低落.
 CPU的挖礦速度是1,功耗相當的情況下:
 那麼GPU大概就是10,
 而ASIC的挖礦速度是2000,。
 Open data也是挖礦,非常慢:
 但你可能有10%機率挖到鑽石. 90%泥土.
App flow
and logic:
取得Open
data 資料
Check
1.internet
2. Server
api alive
Download
in
AsynTask
Gson
parser
Data
ArrayList
& filter
Listview
&
Adapter
User
Condition
(filter) &
User click
marker
→get real
data.
警廣即時路況| 政府資料開放平臺
https://data.gov.tw/dataset/15221
本資料與警廣即時路況查詢網頁至多有1分鐘的時間差,每次取得最後更新的1000
筆路況資料。路況區域︰"A","N","M","S","E"代表"全","北","中","南","東"。
Map api
programming
主要步驟
Get map
ready
Get user’s
gps
permission
GPS
setting
Wait
gps
ready
Map
configura
tion
Place
marker
User disable
gps or gps is
slow
User back to
last page or
exit or rotate
screen
No
internet
Zoom
map
User click
marker
Register
location
listener
耗電問題
沒有
google
play
直播
https://www.youtube.com/watch?v=sG-U76ROyc0
AI engine: gps
input and
event output
Input
latitude
and
longitude
Compare
Data
In 1km
Check
Data is
Valid,
Check
time
TTS
Ui show
1000- 100- 1-
Specify app
permissions
 Android offers two location permissions:
 android.permission.ACCESS_COARSE_LOCATION –
 Allows the API to use WiFi or mobile cell data (or both) to
determine the device's location.
 accuracy approximately equivalent to a city block.
 android.permission.ACCESS_FINE_LOCATION –
 including the Global Positioning System (GPS) as well asWiFi
and mobile cell data.
 Requesting Permissions at RunTime:
 If device is Android 6.0 or app target SDK is 23
 the app has to request those permissions at run time.
Permissions
automatically
merged into
your manifest
 The following permissions are defined in the Google Play services
manifest, and are automatically merged into your app's manifest
at build time.
 You don't need to add them explicitly to your manifest:
 android.permission.INTERNET - Used by theAPI to download map
tiles fromGoogle Maps servers.
 android.permission.ACCESS_NETWORK_STATE -Allows theAPI to
check the connection status in order to determine whether data can
be downloaded.
 <uses-feature android:glEsVersion="0x00020000"
android:required="true"/>
LoactionListe
ner and
LoactionMan
ager
 publicView onCreateView(LayoutInflater inflater,ViewGroup
container, Bundle savedInstanceState) {
 View rootView = inflater.inflate(R.layout.fragment_map,
container, false);
 LocationManager locationManager = (LocationManager)
getActivity().getSystemService(Context.LOCATION_SERVI
CE);

locationManager.requestLocationUpdates(LocationManage
r.GPS_PROVIDER, second, meters, MapFragment.this);
 return rootView;
 }

 當座標有改變,事件監聽器會傳送一個 Location 物件,可
透過 Location 取得當下的經度、緯度、時間、精準度、速
度、海拔等資訊
 @Override
 public void onLocationChanged(Location location) {
 // 緯度 // 經度 // 精準度
 double latitude = location.getLatitude();
 double longitude = location.getLongitude();
 float accuracy= location.getAccuracy();
 }
 //當服務狀態改變時,會透過這個 method 告知
 @Override
 public void onStatusChanged(String provider, int status,
Bundle extras) {
 }
 //當可提供服務時,會透過這個 method 告知
 @Override
 public void onProviderEnabled(String provider) {
 }
 //當服務失效時,會透過這個 method 告知
 @Override
 public void onProviderDisabled(String provider) {

 }
SupportMapFr
agment
or
MapView
or
MapFragment.
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Or
mMapFragment = MapFragment.newInstance();
FragmentTransaction fragmentTransaction =
getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.my_container, mMapFragment);
fragmentTransaction.commit();
Or
public class MainActivity extends FragmentActivity
implements OnMapReadyCallback {
...
}
Map types
 Normal: Typical road map + roads and city names
 Satellite: Satellite photograph data. Road and feature labels are
not visible.
 Hybrid: Satellite photograph with road maps added.
 Terrain: Topographic data. map with mountains, rivers.
Adding a Map
with a Marker
 public class MapsMarkerActivity extends AppCompatActivity
 implementsOnMapReadyCallback {
 @Override
 public void onMapReady(GoogleMapgoogleMap)
 {
 //Add a marker in Sydney,Australia,
 // and move the map's camera to the same location.
 LatLng sydney = new LatLng(-33.852, 151.211);
 googleMap.addMarker(new MarkerOptions().position(sydney)
 .title("Marker in Sydney"));

googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney
));
 }
 }
Marker
clusters
https://developers.google.com/maps/documentation/android-sdk/utility/marker-clustering
ClusterManager
ClusterItem
Google MapsAndroidAPI utility library
bouncing
marker
 http://android-er.blogspot.com/2013/01/implement-bouncing-marker-
for-google.html
android.view.animation.BounceInterpolator;
https://www.youtube.com/watch?v=siE7-zQB6ko
Zoom
1:World
5: Landmass 國家等級
10:City
15: Streets
20: Buildings
Gestures
 Scroll (pan) gestures
 A user can scroll (pan) around the map by dragging the map with
their finger.
 UiSettings.setScrollGesturesEnabled(boolean).
 Tilt gestures (傾斜)
 can tilt the map by placing two fingers on the map and moving
them down or up together to increase or decrease the angle
respectively.
 UiSettings.setTiltGesturesEnabled(boolean).
 Rotate gestures
 by placing two fingers on the map and applying a rotate motion.
 UiSettings.setRotateGesturesEnabled(boolean).
Camera and
View
Tilt (viewing
angle)
( notTile
Overlays)
0 degrees. Vs 45 degrees.
Move the
camera
private static final LatLng SYDNEY = new LatLng(-33.88,151.21);
private static final LatLng MOUNTAIN_VIEW = new LatLng(37.4, -122.1);
private GoogleMap map;
... // Obtain the map from a MapFragment or MapView.
// Move the camera instantly to Sydney with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomIn());
// Zoom out to zoom level 10, animating with a duration of 2 seconds.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
// Construct a CameraPosition focusing on Mountain View and animate the camera to that position.
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(MOUNTAIN_VIEW) // Sets the center of the map to Mountain View
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Zoom in to all
marker
https://youtu.be/hxEuNRXH2yE
My Location
layer
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
// TODO: Before enabling the My Location layer, you must
request
// location permission from the user. This sample does not include
// a request for location permission.
mMap.setMyLocationEnabled(true);
mMap.setOnMyLocationButtonClickListener(this);
mMap.setOnMyLocationClickListener(this);
}
@Override
public void onMyLocationClick(@NonNull Location location) {
Toast.makeText(this, "Current location:n" + location,
Toast.LENGTH_LONG).show();
}
@Override
public boolean onMyLocationButtonClick() {
Toast.makeText(this, "MyLocation button clicked",
Toast.LENGTH_SHORT).show();
// Return false so that we don't consume the event and the
default behavior still occurs
// (the camera animates to the user's current position).
return false;
}
}
Traffic layer
Polylines and
Polygons
@Override
public void onMapReady(GoogleMap googleMap) {
//Add polylines and polygons to the map.This section shows just
// a single polyline. Read the rest of the tutorial to learn more.
Polyline polyline1 = googleMap.addPolyline(new PolylineOptions()
.clickable(true)
.add(
new LatLng(-35.016, 143.321),
new LatLng(-34.747, 145.592),
new LatLng(-34.364, 147.891),
new LatLng(-33.501, 150.217),
new LatLng(-32.306, 149.248),
new LatLng(-32.491, 147.309)));
// Position the map's camera nearAlice Springs in the center of Australia,
// and set the zoom factor so most ofAustralia shows on the screen.
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(newLatLng(-
23.684, 133.903), 4));
// Set listeners for click events.
googleMap.setOnPolylineClickListener(this);
googleMap.setOnPolygonClickListener(this);
}
polyline.setEndCap(new RoundCap());
polyline.setWidth(POLYLINE_STROKE_WIDTH_PX);
polyline.setColor(COLOR_BLACK_ARGB);
polyline.setJointType(JointType.ROUND);
Add a circle in
Sydney
 GoogleMap map;
 Circle circle = map.addCircle(new CircleOptions()
 .center(new LatLng(-33.87365, 151.20689))
 .radius(10000)
 .strokeColor(Color.RED)
 .fillColor(Color.BLUE));
 // in meters
使用地名、地
址查詢位置
使用Geocoder
將經緯度轉地
址
Geocoder geocoder = new Geocoder(act, Locale.getDefault());
try
{
final List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE,
1);
if( addresses != null )
{
final Address returnedAddress = addresses.get(0);
String strReturnedAddress = "";
final int idx_add = returnedAddress.getMaxAddressLineIndex();
for( int i = 0; i < returnedAddress.getAddressLine(idx_add).length(); i++ )
{
if( returnedAddress.getAddressLine(i) != null )
{
strReturnedAddress += (returnedAddress.getAddressLine(i));
}
}
….
lstAddress.get(0).getCountryName(); //台灣省
lstAddress.get(0).getAdminArea(); //台北市
lstAddress.get(0).getLocality(); //中正區
lstAddress.get(0).getThoroughfare(); //信陽街(包含路巷弄)
lstAddress.get(0).getFeatureName(); //會得到33(號)
lstAddress.get(0).getPostalCode(); //會得到100(郵遞區號)
Geocoder geoCoder = new Geocoder(context, Locale.getDefault());
List<Address> addressLocation = geoCoder.getFromLocationName(addressString, 1);
double latitude = addressLocation.get(0).getLatitude();
double longitude = addressLocation.get(0).getLongitude();
Ps: addressString:地址
坑:
正式發佈前測
試報告
我還可以免費
使用Google
地圖平台嗎?
可以。自 2018 年 7 月 16 日起,只要您啟用計費方案,即
可獲得每月 $200 美元的免費額度, 可用於地圖、路線或
Place.
根據目前數百萬位使用者的 Google API 使用情況來判斷,
大部分都在此額度範圍內,多半還是可以繼續 免費使用
Google 地圖.
每月抵免額$200
對應的免費用量
每月用量範圍
(每千次呼叫價格)
0-100,000 100,001-500,000
行動版原生靜態地圖 載入次數不限 $0.00 $0.00
行動版原生動態地圖 載入次數不限 $0.00 $0.00
嵌入 載入次數不限 $0.00 $0.00
進階嵌入 最多 14,000 次載入 $14.00 $11.20
靜態地圖 最多 100,000次載入 $2.00 $1.60
動態地圖 最多 28,000 次載入 $7.00 $5.60
靜態街景服務 最多 28,000 次全景 $7.00 $5.60
動態街景服務 最多 14,000 次全景 $14.00 $11.20
Ps: A web page or application that displays a map using the Maps JavaScript API.
MapsAndroid
API key
 Go to the Google Cloud Platform Console in your browser
 Key type: Android-restricted
 app's SHA-1 fingerp rint
 BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75
 com.example.android.mapexample
 <meta-data
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />
 <meta-data
 android:name="com.google.android.geo.API_KEY"
 android:value="AIzaSyBdVl-cTICxwYKrZ95SuvNw7daMuDt1KG0"/>
 For backwards compatibility, the API also supports the name
com.google.android.maps.v2.API_KEY. This legacy name allows
authentication to the Android Maps API v2 only.
坑:
Api key
與play console
簽名金鑰的問
題
坑:
比較時間的問
題
Compare date
and time issue
public static final SimpleDateFormat sdf_datetime = new
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final Date time2 = PBSWarning.sdf_datetime.parse(date1 + " " + time1);
Calendar cal1 = Calendar.getInstance();
cal1.setTime(time2);
cal_now = Calendar.getInstance();
cal_now.add(Calendar.HOUR_OF_DAY, -2);
x2 = cal1.getTime();
x_now = cal_now.getTime();
final boolean b_is_in_range = x_now.before(x2);
return b_is_in_range;
Data
time
now
time
心得 &
未來與發展
 Google map很好用,但他實在太巨大, 耗資源,這樣子就留給我們
custom的空間.留了一條生路給我們去設計新app.
 沒人用的app根本無法發展!
 寫一個app沒有人用,需要行銷後才有人用,行銷要錢.
 寫程式的苦: 坐下來,開始寫,一坐就是12小時,很痛苦.
app統計資料
DAU:(Daily
Active User)
收益=( App數量 -正比- App DAU -正比- CPC)
-固定成本-人工成本
Ios 版 開發的
困難

More Related Content

Similar to 20180823 警廣地圖APP開發與踩到的n個坑

097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión
GeneXus
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
gerbille
 

Similar to 20180823 警廣地圖APP開發與踩到的n個坑 (20)

HTML5勉強会#23_GeoHex
HTML5勉強会#23_GeoHexHTML5勉強会#23_GeoHex
HTML5勉強会#23_GeoHex
 
Knock knock! Who's there? Doze. - Yonatan Levin
Knock knock! Who's there? Doze. - Yonatan Levin Knock knock! Who's there? Doze. - Yonatan Levin
Knock knock! Who's there? Doze. - Yonatan Levin
 
Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.
 
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinGet the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
 
Maps
MapsMaps
Maps
 
report
reportreport
report
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptx
 
Battery Efficient Location Services
Battery Efficient Location ServicesBattery Efficient Location Services
Battery Efficient Location Services
 
Core Location in iOS
Core Location in iOSCore Location in iOS
Core Location in iOS
 
The Wonderful-Amazing-Orientation-Motion-Sensormatic Machine
The Wonderful-Amazing-Orientation-Motion-Sensormatic MachineThe Wonderful-Amazing-Orientation-Motion-Sensormatic Machine
The Wonderful-Amazing-Orientation-Motion-Sensormatic Machine
 
Developing Windows Phone Apps with Maps and Location Services
Developing Windows Phone Apps with Maps and Location ServicesDeveloping Windows Phone Apps with Maps and Location Services
Developing Windows Phone Apps with Maps and Location Services
 
HMotion: An Algorithm for Human Motion Detection
HMotion: An Algorithm for Human Motion DetectionHMotion: An Algorithm for Human Motion Detection
HMotion: An Algorithm for Human Motion Detection
 
Zenly - Reverse geocoding
Zenly - Reverse geocodingZenly - Reverse geocoding
Zenly - Reverse geocoding
 
097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión097 smart devices-con_las_aplicaciones_de_gestión
097 smart devices-con_las_aplicaciones_de_gestión
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
AUGMENTED_REALITY
AUGMENTED_REALITYAUGMENTED_REALITY
AUGMENTED_REALITY
 
google play service 7.8 & new tech in M
google play service 7.8 & new tech in M google play service 7.8 & new tech in M
google play service 7.8 & new tech in M
 
Y Map Mashup Camp
Y Map Mashup CampY Map Mashup Camp
Y Map Mashup Camp
 
KODE JS POKENNNNN
KODE JS POKENNNNNKODE JS POKENNNNN
KODE JS POKENNNNN
 

Recently uploaded

Top profile Call Girls In dewas [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In dewas [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In dewas [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In dewas [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
Illustrative History and Influence of Board Games - Thesis.pptx
Illustrative History and Influence of Board Games - Thesis.pptxIllustrative History and Influence of Board Games - Thesis.pptx
Illustrative History and Influence of Board Games - Thesis.pptx
HenriSandoval
 
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdfJohn Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
Excavator
 
一比一原版伯明翰城市大学毕业证成绩单留信学历认证
一比一原版伯明翰城市大学毕业证成绩单留信学历认证一比一原版伯明翰城市大学毕业证成绩单留信学历认证
一比一原版伯明翰城市大学毕业证成绩单留信学历认证
62qaf0hi
 
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
nirzagarg
 
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
ezgenuh
 
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
ozave
 
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
Health
 

Recently uploaded (20)

Top profile Call Girls In dewas [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In dewas [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In dewas [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In dewas [ 7014168258 ] Call Me For Genuine Models We ...
 
Illustrative History and Influence of Board Games - Thesis.pptx
Illustrative History and Influence of Board Games - Thesis.pptxIllustrative History and Influence of Board Games - Thesis.pptx
Illustrative History and Influence of Board Games - Thesis.pptx
 
What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'
What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'
What Does It Mean When Mercedes Says 'ESP Inoperative See Owner's Manual'
 
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdfJohn Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
John Deere Tractors 5415 Diagnostic Repair Service Manual.pdf
 
Is Your Volvo XC90 Displaying Anti-Skid Service Required Alert Here's Why
Is Your Volvo XC90 Displaying Anti-Skid Service Required Alert Here's WhyIs Your Volvo XC90 Displaying Anti-Skid Service Required Alert Here's Why
Is Your Volvo XC90 Displaying Anti-Skid Service Required Alert Here's Why
 
Mercedes Check Engine Light Solutions Precision Service for Peak Performance
Mercedes Check Engine Light Solutions Precision Service for Peak PerformanceMercedes Check Engine Light Solutions Precision Service for Peak Performance
Mercedes Check Engine Light Solutions Precision Service for Peak Performance
 
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best ServiceMuslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
 
一比一原版伯明翰城市大学毕业证成绩单留信学历认证
一比一原版伯明翰城市大学毕业证成绩单留信学历认证一比一原版伯明翰城市大学毕业证成绩单留信学历认证
一比一原版伯明翰城市大学毕业证成绩单留信学历认证
 
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Darbhanga [ 7014168258 ] Call Me For Genuine Models...
 
John deere 7200r 7230R 7260R Problems Repair Manual
John deere 7200r 7230R 7260R Problems Repair ManualJohn deere 7200r 7230R 7260R Problems Repair Manual
John deere 7200r 7230R 7260R Problems Repair Manual
 
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
 
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
 
JOHN DEERE 7200R 7215R 7230R 7260R 7280R TECHNICAL SERVICE PDF MANUAL 2680PGS...
JOHN DEERE 7200R 7215R 7230R 7260R 7280R TECHNICAL SERVICE PDF MANUAL 2680PGS...JOHN DEERE 7200R 7215R 7230R 7260R 7280R TECHNICAL SERVICE PDF MANUAL 2680PGS...
JOHN DEERE 7200R 7215R 7230R 7260R 7280R TECHNICAL SERVICE PDF MANUAL 2680PGS...
 
Is Your BMW PDC Malfunctioning Discover How to Easily Reset It
Is Your BMW PDC Malfunctioning Discover How to Easily Reset ItIs Your BMW PDC Malfunctioning Discover How to Easily Reset It
Is Your BMW PDC Malfunctioning Discover How to Easily Reset It
 
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
+97470301568>>buy vape oil,thc oil weed,hash and cannabis oil in qatar doha}}
 
Faridabad Call Girls ₹7.5k Pick Up & Drop With Cash Payment 8168257667 Call G...
Faridabad Call Girls ₹7.5k Pick Up & Drop With Cash Payment 8168257667 Call G...Faridabad Call Girls ₹7.5k Pick Up & Drop With Cash Payment 8168257667 Call G...
Faridabad Call Girls ₹7.5k Pick Up & Drop With Cash Payment 8168257667 Call G...
 
Is Your Mercedes Benz Trunk Refusing To Close Here's What Might Be Wrong
Is Your Mercedes Benz Trunk Refusing To Close Here's What Might Be WrongIs Your Mercedes Benz Trunk Refusing To Close Here's What Might Be Wrong
Is Your Mercedes Benz Trunk Refusing To Close Here's What Might Be Wrong
 
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
Washim Call Girls 📞9332606886 Call Girls in Washim Escorts service book now C...
 
T.L.E 5S's (Seiri, Seiton, Seiso, Seiketsu, Shitsuke).pptx
T.L.E 5S's (Seiri, Seiton, Seiso, Seiketsu, Shitsuke).pptxT.L.E 5S's (Seiri, Seiton, Seiso, Seiketsu, Shitsuke).pptx
T.L.E 5S's (Seiri, Seiton, Seiso, Seiketsu, Shitsuke).pptx
 
Electronic Stability Program. (ESP).pptx
Electronic Stability Program. (ESP).pptxElectronic Stability Program. (ESP).pptx
Electronic Stability Program. (ESP).pptx
 

20180823 警廣地圖APP開發與踩到的n個坑

  • 1. 警廣地圖APP開發 與 踩到的n個坑 (android google map 程式設計 一定要知道的事) Mark Chiu Markchiu.tw@gmail.com 2018.8.23.TaipeiTaiwan.
  • 3. 台灣車禍發生 率超越美日韓  台灣車禍106年  肇事率(1.4件/百輛)  死亡率(0.7人/萬輛)  受傷率(1.8人/百輛)  每5小時又9分鐘  台灣就有1人死於交通事故
  • 4. Opendata挖礦  如果我跟你說:  我知道一個寶藏:那是一個充滿黃金的地方….  You pay your time, you got money.  Open dateTaiwan .國人專屬.  還有: 中國,美加.英法俄 印度 日韓 ,南美, 中東  台灣政府的行政效率低落.  CPU的挖礦速度是1,功耗相當的情況下:  那麼GPU大概就是10,  而ASIC的挖礦速度是2000,。  Open data也是挖礦,非常慢:  但你可能有10%機率挖到鑽石. 90%泥土.
  • 5. App flow and logic: 取得Open data 資料 Check 1.internet 2. Server api alive Download in AsynTask Gson parser Data ArrayList & filter Listview & Adapter User Condition (filter) & User click marker →get real data. 警廣即時路況| 政府資料開放平臺 https://data.gov.tw/dataset/15221 本資料與警廣即時路況查詢網頁至多有1分鐘的時間差,每次取得最後更新的1000 筆路況資料。路況區域︰"A","N","M","S","E"代表"全","北","中","南","東"。
  • 6. Map api programming 主要步驟 Get map ready Get user’s gps permission GPS setting Wait gps ready Map configura tion Place marker User disable gps or gps is slow User back to last page or exit or rotate screen No internet Zoom map User click marker Register location listener 耗電問題 沒有 google play
  • 8. AI engine: gps input and event output Input latitude and longitude Compare Data In 1km Check Data is Valid, Check time TTS Ui show 1000- 100- 1-
  • 9. Specify app permissions  Android offers two location permissions:  android.permission.ACCESS_COARSE_LOCATION –  Allows the API to use WiFi or mobile cell data (or both) to determine the device's location.  accuracy approximately equivalent to a city block.  android.permission.ACCESS_FINE_LOCATION –  including the Global Positioning System (GPS) as well asWiFi and mobile cell data.  Requesting Permissions at RunTime:  If device is Android 6.0 or app target SDK is 23  the app has to request those permissions at run time.
  • 10. Permissions automatically merged into your manifest  The following permissions are defined in the Google Play services manifest, and are automatically merged into your app's manifest at build time.  You don't need to add them explicitly to your manifest:  android.permission.INTERNET - Used by theAPI to download map tiles fromGoogle Maps servers.  android.permission.ACCESS_NETWORK_STATE -Allows theAPI to check the connection status in order to determine whether data can be downloaded.  <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
  • 11. LoactionListe ner and LoactionMan ager  publicView onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {  View rootView = inflater.inflate(R.layout.fragment_map, container, false);  LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVI CE);  locationManager.requestLocationUpdates(LocationManage r.GPS_PROVIDER, second, meters, MapFragment.this);  return rootView;  }   當座標有改變,事件監聽器會傳送一個 Location 物件,可 透過 Location 取得當下的經度、緯度、時間、精準度、速 度、海拔等資訊  @Override  public void onLocationChanged(Location location) {  // 緯度 // 經度 // 精準度  double latitude = location.getLatitude();  double longitude = location.getLongitude();  float accuracy= location.getAccuracy();  }  //當服務狀態改變時,會透過這個 method 告知  @Override  public void onStatusChanged(String provider, int status, Bundle extras) {  }  //當可提供服務時,會透過這個 method 告知  @Override  public void onProviderEnabled(String provider) {  }  //當服務失效時,會透過這個 method 告知  @Override  public void onProviderDisabled(String provider) {   }
  • 12. SupportMapFr agment or MapView or MapFragment. <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" tools:context=".MapsActivity" android:name="com.google.android.gms.maps.SupportMapFragment" /> MapFragment mapFragment = (MapFragment) getFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); Or mMapFragment = MapFragment.newInstance(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.my_container, mMapFragment); fragmentTransaction.commit(); Or public class MainActivity extends FragmentActivity implements OnMapReadyCallback { ... }
  • 13. Map types  Normal: Typical road map + roads and city names  Satellite: Satellite photograph data. Road and feature labels are not visible.  Hybrid: Satellite photograph with road maps added.  Terrain: Topographic data. map with mountains, rivers.
  • 14. Adding a Map with a Marker  public class MapsMarkerActivity extends AppCompatActivity  implementsOnMapReadyCallback {  @Override  public void onMapReady(GoogleMapgoogleMap)  {  //Add a marker in Sydney,Australia,  // and move the map's camera to the same location.  LatLng sydney = new LatLng(-33.852, 151.211);  googleMap.addMarker(new MarkerOptions().position(sydney)  .title("Marker in Sydney"));  googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney ));  }  }
  • 18. Gestures  Scroll (pan) gestures  A user can scroll (pan) around the map by dragging the map with their finger.  UiSettings.setScrollGesturesEnabled(boolean).  Tilt gestures (傾斜)  can tilt the map by placing two fingers on the map and moving them down or up together to increase or decrease the angle respectively.  UiSettings.setTiltGesturesEnabled(boolean).  Rotate gestures  by placing two fingers on the map and applying a rotate motion.  UiSettings.setRotateGesturesEnabled(boolean).
  • 19. Camera and View Tilt (viewing angle) ( notTile Overlays) 0 degrees. Vs 45 degrees.
  • 20. Move the camera private static final LatLng SYDNEY = new LatLng(-33.88,151.21); private static final LatLng MOUNTAIN_VIEW = new LatLng(37.4, -122.1); private GoogleMap map; ... // Obtain the map from a MapFragment or MapView. // Move the camera instantly to Sydney with a zoom of 15. map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 15)); // Zoom in, animating the camera. map.animateCamera(CameraUpdateFactory.zoomIn()); // Zoom out to zoom level 10, animating with a duration of 2 seconds. map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); // Construct a CameraPosition focusing on Mountain View and animate the camera to that position. CameraPosition cameraPosition = new CameraPosition.Builder() .target(MOUNTAIN_VIEW) // Sets the center of the map to Mountain View .zoom(17) // Sets the zoom .bearing(90) // Sets the orientation of the camera to east .tilt(30) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
  • 21. Zoom in to all marker https://youtu.be/hxEuNRXH2yE
  • 22. My Location layer @Override public void onMapReady(GoogleMap map) { mMap = map; // TODO: Before enabling the My Location layer, you must request // location permission from the user. This sample does not include // a request for location permission. mMap.setMyLocationEnabled(true); mMap.setOnMyLocationButtonClickListener(this); mMap.setOnMyLocationClickListener(this); } @Override public void onMyLocationClick(@NonNull Location location) { Toast.makeText(this, "Current location:n" + location, Toast.LENGTH_LONG).show(); } @Override public boolean onMyLocationButtonClick() { Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT).show(); // Return false so that we don't consume the event and the default behavior still occurs // (the camera animates to the user's current position). return false; } }
  • 24. Polylines and Polygons @Override public void onMapReady(GoogleMap googleMap) { //Add polylines and polygons to the map.This section shows just // a single polyline. Read the rest of the tutorial to learn more. Polyline polyline1 = googleMap.addPolyline(new PolylineOptions() .clickable(true) .add( new LatLng(-35.016, 143.321), new LatLng(-34.747, 145.592), new LatLng(-34.364, 147.891), new LatLng(-33.501, 150.217), new LatLng(-32.306, 149.248), new LatLng(-32.491, 147.309))); // Position the map's camera nearAlice Springs in the center of Australia, // and set the zoom factor so most ofAustralia shows on the screen. googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(newLatLng(- 23.684, 133.903), 4)); // Set listeners for click events. googleMap.setOnPolylineClickListener(this); googleMap.setOnPolygonClickListener(this); } polyline.setEndCap(new RoundCap()); polyline.setWidth(POLYLINE_STROKE_WIDTH_PX); polyline.setColor(COLOR_BLACK_ARGB); polyline.setJointType(JointType.ROUND);
  • 25. Add a circle in Sydney  GoogleMap map;  Circle circle = map.addCircle(new CircleOptions()  .center(new LatLng(-33.87365, 151.20689))  .radius(10000)  .strokeColor(Color.RED)  .fillColor(Color.BLUE));  // in meters
  • 26. 使用地名、地 址查詢位置 使用Geocoder 將經緯度轉地 址 Geocoder geocoder = new Geocoder(act, Locale.getDefault()); try { final List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1); if( addresses != null ) { final Address returnedAddress = addresses.get(0); String strReturnedAddress = ""; final int idx_add = returnedAddress.getMaxAddressLineIndex(); for( int i = 0; i < returnedAddress.getAddressLine(idx_add).length(); i++ ) { if( returnedAddress.getAddressLine(i) != null ) { strReturnedAddress += (returnedAddress.getAddressLine(i)); } } …. lstAddress.get(0).getCountryName(); //台灣省 lstAddress.get(0).getAdminArea(); //台北市 lstAddress.get(0).getLocality(); //中正區 lstAddress.get(0).getThoroughfare(); //信陽街(包含路巷弄) lstAddress.get(0).getFeatureName(); //會得到33(號) lstAddress.get(0).getPostalCode(); //會得到100(郵遞區號) Geocoder geoCoder = new Geocoder(context, Locale.getDefault()); List<Address> addressLocation = geoCoder.getFromLocationName(addressString, 1); double latitude = addressLocation.get(0).getLatitude(); double longitude = addressLocation.get(0).getLongitude(); Ps: addressString:地址
  • 28. 我還可以免費 使用Google 地圖平台嗎? 可以。自 2018 年 7 月 16 日起,只要您啟用計費方案,即 可獲得每月 $200 美元的免費額度, 可用於地圖、路線或 Place. 根據目前數百萬位使用者的 Google API 使用情況來判斷, 大部分都在此額度範圍內,多半還是可以繼續 免費使用 Google 地圖. 每月抵免額$200 對應的免費用量 每月用量範圍 (每千次呼叫價格) 0-100,000 100,001-500,000 行動版原生靜態地圖 載入次數不限 $0.00 $0.00 行動版原生動態地圖 載入次數不限 $0.00 $0.00 嵌入 載入次數不限 $0.00 $0.00 進階嵌入 最多 14,000 次載入 $14.00 $11.20 靜態地圖 最多 100,000次載入 $2.00 $1.60 動態地圖 最多 28,000 次載入 $7.00 $5.60 靜態街景服務 最多 28,000 次全景 $7.00 $5.60 動態街景服務 最多 14,000 次全景 $14.00 $11.20 Ps: A web page or application that displays a map using the Maps JavaScript API.
  • 29. MapsAndroid API key  Go to the Google Cloud Platform Console in your browser  Key type: Android-restricted  app's SHA-1 fingerp rint  BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75  com.example.android.mapexample  <meta-data  android:name="com.google.android.gms.version"  android:value="@integer/google_play_services_version" />  <meta-data  android:name="com.google.android.geo.API_KEY"  android:value="AIzaSyBdVl-cTICxwYKrZ95SuvNw7daMuDt1KG0"/>  For backwards compatibility, the API also supports the name com.google.android.maps.v2.API_KEY. This legacy name allows authentication to the Android Maps API v2 only.
  • 31. 坑: 比較時間的問 題 Compare date and time issue public static final SimpleDateFormat sdf_datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); final Date time2 = PBSWarning.sdf_datetime.parse(date1 + " " + time1); Calendar cal1 = Calendar.getInstance(); cal1.setTime(time2); cal_now = Calendar.getInstance(); cal_now.add(Calendar.HOUR_OF_DAY, -2); x2 = cal1.getTime(); x_now = cal_now.getTime(); final boolean b_is_in_range = x_now.before(x2); return b_is_in_range; Data time now time
  • 32. 心得 & 未來與發展  Google map很好用,但他實在太巨大, 耗資源,這樣子就留給我們 custom的空間.留了一條生路給我們去設計新app.  沒人用的app根本無法發展!  寫一個app沒有人用,需要行銷後才有人用,行銷要錢.  寫程式的苦: 坐下來,開始寫,一坐就是12小時,很痛苦.
  • 34. DAU:(Daily Active User) 收益=( App數量 -正比- App DAU -正比- CPC) -固定成本-人工成本