xây dựng phần mềm dự báo thời tiết

67 811 1
xây dựng phần mềm dự báo thời tiết

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Trước khi bắt tay vào lập trình bài này thì ta xem sơ qua cấu trúc JSON khi kiểm tra thời tiết của một địa điểm nào đó, ví dụ ở Thành Phố Hồ Chí Minh:http:api.openweathermap.orgdata2.5weather?q=hồ chí minhappid=be8d3e323de722ff78208a7dbb2dcd6fhay dùng kinh độ vĩ độ (để áp dụng cho chức năng đầu tiên là xem thời tiết tại địa điểm hiện tại, theo địa chỉ bất kỳ, hay xem trên Google Map):http:api.openweathermap.orgdata2.5weather?lat=10.778182lon=106.665504appid=be8d3e323de722ff78208a7dbb2dcd6fTa được kết quả tương tự như sau: Các source code bạn tự nối đuôi appid mà Tui đã chỉ ở trên là có thể chạy tốt.End update 13122015—————————————–Việc phân tích cấu trúc JSON để viết Java class các bạn đã được học kỹ ở các bài trước rồi, nên bài này Tui không nói nữa mà Tui chỉ show Mô hình Java class đã viết ra như sau (Bạn tự viết): – Ta sẽ dùng GSon để chuyển JSON qua Java class, từ đó dễ dàng cho việc sử dụng lấy thông tin dự báo thời tiết.– Còn dưới đây là cấu trúc JSON cho trường hợp dự báo các ngày khác (Daily):Ví dụ:http:api.openweathermap.orgdata2.5forecastdaily?lat=10.778182lon=106.665504cnt=10Hay:http:api.openweathermap.orgdata2.5forecastdaily?q=hồ chí minhcnt=10Thì ta có kết quả với cấu trúc JSON khá khác cho với trường hợp trên như sau: –> Bạn tự phân tích cấu trúc ở trên để viết Java Class cho trường hợp Daily (chức năng số 3).Trong Project này Tui sẽ thực hiện 3 chức năng (thời tiết địa điểm hiện tại của thiết bị, xem thời tiết theo địa điểm nhập bất kỳ và xem thời tiết trên Google Map), còn chức năng dự báo ngày kế tiếp các bạn tiếp tục thực hiện.

Xây dựng phần mềm dự báo thời tiết Tui muốn tổng hợp tập Google Map, Đa tiến trình, JSon, Webservice… để xây dựng phần mềm dự báo thời tiết đơn giản hình đây: – Phần mềm có chức mô tả trên, để làm bạn cần phải có kiến thức sau: Đồng thời nghiên cứu thêm API Open Weather Map(Hỗ trợ xem thời tiết hầu hết nơi giới, đánh giá API cấp webservice dự báo thời tiết tốt nay) Cập nhật ngày 13/12/2015 Để sử dụng API bạn cần đăng nhập để lấy appid, chi tiết đọc : http://openweathermap.org/appid Khi đăng ký đăng nhập thành công, bạn có API key bên dưới: http://api.openweathermap.org/data/2.5/forecast/daily? lat=10.778182&lon=106.665504&cnt=1&appid=be8d3e323de722ff78208a7dbb2dc d6f Ví dụ 0: Xem thời tiết Thành Phố Hồ Chí Minh: http://api.openweathermap.org/data/2.5/weather?q=hồ chí minh&appid=be8d3e323de722ff78208a7dbb2dcd6f Ví dụ 1: Xem thời tiết Đà Lạt http://api.openweathermap.org/data/2.5/forecast/daily?q=đà lạ t&appid=be8d3e323de722ff78208a7dbb2dcd6f Ví dụ 2: Xem thời tiết Đà Lạt sau 15 ngày nào: http://api.openweathermap.org/data/2.5/forecast/daily?q=đà lạt&cnt=1 5&appid=be8d3e323de722ff78208a7dbb2dcd6f Ví dụ 3: Xem thời tiết Kinh độ Vĩ độ (ứng dụng hiển thị Google Map) http://api.openweathermap.org/data/2.5/forecast/daily? lat=35&lon=139&cnt=10&mode=json&appid=be8d3e323de722ff78208a7dbb2dcd6 f Chi tiết hướng dẫn sử dụng: http://openweathermap.org/api Các bạn tranh thủ ôn lại sau Tui trình bày chi tiết bước cách thực dự án Trước bắt tay vào lập trình ta xem sơ qua cấu trúc JSON kiểm tra thời tiết địa điểm đó, ví dụ Thành Phố Hồ Chí Minh: http://api.openweathermap.org/data/2.5/weather?q=hồ chí minh&appid=be8d3e323de722ff78208a7dbb2dcd6f hay dùng kinh độ vĩ độ (để áp dụng cho chức xem thời tiết địa điểm tại, theo địa bất kỳ, hay xem Google Map): http://api.openweathermap.org/data/2.5/weather? lat=10.778182&lon=106.665504&appid=be8d3e323de722ff78208a7dbb2dcd6f Ta kết tương tự sau: Các source code bạn tự nối đuôi appid mà Tui chạy tốt End update 13/12/2015 —————————————– Việc phân tích cấu trúc JSON để viết Java class bạn học kỹ trước rồi, nên Tui không nói mà Tui show Mô hình Java class viết sau (Bạn tự viết): – Ta dùng GSon để chuyển JSON qua Java class, từ dễ dàng cho việc sử dụng lấy thông tin dự báo thời tiết – Còn cấu trúc JSON cho trường hợp dự báo ngày khác (Daily): Ví dụ: http://api.openweathermap.org/data/2.5/forecast/daily? lat=10.778182&lon=106.665504&cnt=10 Hay: http://api.openweathermap.org/data/2.5/forecast/daily?q=hồ chí minh&cnt=10 Thì ta có kết với cấu trúc JSON khác cho với trường hợp sau: –> Bạn tự phân tích cấu trúc để viết Java Class cho trường hợp Daily (chức số 3) Trong Project Tui thực chức (thời tiết địa điểm thiết bị, xem thời tiết theo địa điểm nhập xem thời tiết Google Map), chức dự báo ngày bạn tiếp tục thực Tui có cấu trúc tập tin, class dự án sau: – Tui chụp hình sử dụng phần mềm dự báo thời tiết sau: 1) Từ hình chính, bấm vào “Thời tiết địa điểm thiết bị”: Chương trình hiển thị thông báo chi tiết dự báo thời tiết sau: Ta thấy chi tiết địa điểm thiết bị (vị trị tương đối phạm vi thiết bị), ta thấy nhiệt độ, bầu trời hình có nắng, có mây, có mưa…, tốc độ gió, áp suất… 2) Từ hình chính, bấm vào “Xem thời tiết theo địa điểm nhập bất kỳ”: Chương trình hiển thị hình cho phép nhập địa bất kỳ, chọn tỉnh thành có sẵn Việt Nam (muốn địa điểm khác Việt Nam hay giới tự gõ địa vào), hình chọn địa điểm: Nếu ta chọn nhập địa điểm bất kỳ, ví dụ Hồ Chí Minh, ta có kết sau: Ở hình ta thấy đấy, Hồ Chí Minh có mưa nhiệt độ nóng 34.2 độ C Đúng thời điểm Tui post hình lên Sài gòn mưa nóng le lưỡi 3) Tại hình chính, chọn “Xem thời tiết Google Map”, chương trình tự động hiển thị thời tiết vị trí đồ, cho phép bạn nhấn chọn địa điểm đồ để xem thời tiết Đây chức thú vị coding phức tạp Ta có kết quả: Nhớ bạn nhấn chọn vị trí khác để xem thời tiết, ví dụ Tui chọn Nguyễn văn Trỗi: 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 Intent i=getIntent(); //lấy địa từ bên ChooseAddressActivity gửi qua: String q=i.getStringExtra("ADDRESS"); WeatherAsyncTask task=new WeatherAsyncTask(this,q); task.execute(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present getMenuInflater().inflate(R.menu.menu_weather_by_address, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } -Chức cuối Tui muốn hướng dẫn xem thời tiết vị trí đồ (lần mở lên hệ thống hiển thị thời tiết vị trí thiết bị lên đồ, sau người sử dụng muốn xem nơi khác cần nhấn vào vị trí đồ, chức tiện lợi): – Chức ta cần xử lý coding phức tạp chút xíu, cần phải xử lý custom InfoWindowAdapter cho việc hiển thị giao diện khác nên đồ xác định vị trí mà người sử dụng chọn đồ di chuyển hiển thị chi tiết thời tiết địa – Bạn ý để hiển thị Map Android Studio đơn giản nhiều so với Eclipse Android Studio hỗ trợ tốt chức – Ta cần tạo Google Map Activity tên WeatherMapsActivity sau: – Bấm chuột phải vào Package/ chọn New/ chọn Google/ chọn Google Maps Activity: – Sau hình tạo activity hiển thị lên, bạn đặt tên WeatherMapsActivity hệ thống tạo layout tương thích để hiển thị Map (activity_weather_maps.xml): <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="com.tranduythanh.weatherprediction.WeatherMapsActivity" android:name="com.google.android.gms.maps.SupportMapFragment" /> Và lớp WeatherMapsActivity kế thừa từ FragmentActivity Đồng thời phát sinh thêm file google_maps_api.xml để lưu trữ KEY sử dụng Map hướng dẫn trước (bạn cần tự tạo để lấy KEY dán vào đây): Ở bạn cần làm theo bước: Copy toàn liệu dòng mà tui đánh dấu số 1, đưa vào link vùng Tui đánh dấu số (cách tạo key hướng dẫn từ trước Map, bạn tự coi lại), sau tạo Key truy suất MAP, bạn dán Key vào vùng số Ở vùng Số hệ thông có tự đặt tên google_maps_key – Sau bạn mở AndroidManifest lên để quát sát có đây: Bạn thấy đấy, đơn giản nhiều, tự làm giùm cho – Tiếp theo ta tiến hành coding để xử lý cho cho thời tiết map: – Tạo lớp MyInfoWindowAdapter (sử dụng chung Layout xem thời tiết đề cập trên) để hiển thị lên Map: 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package com.tranduythanh.weatherprediction; import import import import import import import import import android.app.Activity; android.graphics.Bitmap; android.graphics.Color; android.location.Address; android.location.Geocoder; android.location.Location; android.view.View; android.widget.ImageView; android.widget.TextView; import import import import import com.google.android.gms.maps.GoogleMap; com.google.android.gms.maps.model.Marker; com.tranduythanh.model.OpenWeatherJSon; com.tranduythanh.utils.TypePrediction; com.tranduythanh.utils.WeatherAsyncTask; import import import import import import java.io.IOException; java.text.DecimalFormat; java.text.NumberFormat; java.util.Date; java.util.List; java.util.Locale; /** * Created by drthanh on 12/05/2015 */ public class MyInfoWindowAdapter implements GoogleMap.InfoWindowAdapter { private Activity context; 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 70 71 72 73 74 75 76 77 Marker maker=null; OpenWeatherJSon openWeatherJSon=null; Bitmap myBitmap=null; NumberFormat format = new DecimalFormat("#0.0"); double latitude; double longitude; public MyInfoWindowAdapter(Activity context) { this.context=context; } public MyInfoWindowAdapter(OpenWeatherJSon openWeatherJSon,Bitmap myBitmap,Marker maker,Activity context) { this(context); this.maker=maker; this.openWeatherJSon=openWeatherJSon; this.myBitmap=myBitmap; } public MyInfoWindowAdapter(OpenWeatherJSon openWeatherJSon,Bitmap myBitmap,Marker maker,Activity context,double latitude,double longitude) { this(openWeatherJSon,myBitmap,maker,context); this.latitude=latitude; this.longitude=longitude; } @Override public View getInfoWindow(Marker marker) { View v = this.context.getLayoutInflater().inflate(R.layout.activity_weather_curren t_location, null); TextView txtTemperature=(TextView) v.findViewById(R.id.txtTemperature); TextView txtCurrentAddressName=(TextView) v.findViewById(R.id.txtCurrentAddressName); ImageView imageView=(ImageView) v.findViewById(R.id.imgBauTroi); TextView txtMaxtemp=(TextView) v.findViewById(R.id.txtMaxTemp); TextView txtMinTemp=(TextView) v.findViewById(R.id.txtMinTemp); TextView txtWind=(TextView) v.findViewById(R.id.txtWind); TextView txtCloudliness= (TextView) v.findViewById(R.id.txtCloudliness); TextView txtPressure= (TextView) v.findViewById(R.id.txtPressure); TextView txtHumidty= (TextView) v.findViewById(R.id.txtHumidty); TextView txtSunrise= (TextView) v.findViewById(R.id.txtSunrise); TextView txtSunset= (TextView) v.findViewById(R.id.txtSunset); double temperature=openWeatherJSon.getMain().getTemp()-273.15; String maxtemp= format.format(openWeatherJSon.getMain().getTemp_max()273.15)+"°C"; String mintemp= format.format(openWeatherJSon.getMain().getTemp_min()273.15)+"°C"; String wind= openWeatherJSon.getWind().getSpeed()+" m/s"; String mesg = openWeatherJSon.getWeather().get(0).getMain(); // Translator translate = Translator.getInstance(); // String cloudiness=mesg+" ("+translate.translate(mesg, Language.ENGLISH, Language.VIETNAMESE)+")"; String cloudiness=mesg; String pressure= openWeatherJSon.getMain().getPressure()+" hpa"; String humidity=openWeatherJSon.getMain().getHumidity()+" %"; Date timeSunrise = new Date(openWeatherJSon.getSys().getSunrise()*1000); String Sunrise= timeSunrise.getHours()+":"+timeSunrise.getMinutes()+" AM"; Date timeSunSet = new Date(openWeatherJSon.getSys().getSunset()*1000); String sunset= timeSunSet.getHours()+":"+timeSunSet.getMinutes(); txtTemperature.setText(format.format(temperature)+"°C"); 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 imageView.setImageBitmap(myBitmap); txtMaxtemp.setText(maxtemp); txtMinTemp.setText(mintemp); txtWind.setText(wind); txtCloudliness.setText(cloudiness); txtPressure.setText(pressure); txtHumidty.setText(humidity); txtSunrise.setText(Sunrise); txtSunset.setText(sunset); try { Geocoder geocoder; List<Address> addresses; geocoder = new Geocoder(this.context, Locale.getDefault()); addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here represent max location result to returned, by documents it recommended to Address address=null; if(addresses.size()>0) address=addresses.get(0); if(address!=null) { txtCurrentAddressName.setText(address.getAddressLine(0)); /*String city = address.getLocality(); String state = address.getAdminArea(); String country = address.getCountryName(); String postalCode = address.getPostalCode(); String knownName = address.getFeatureName();*/ } } catch (IOException e) { e.printStackTrace(); } v.setBackgroundColor (Color.WHITE); return v; } @Override public View getInfoContents(Marker marker) { return null; } } 11 11 11 11 11 12 12 12 12 12 12 – Cuối ta xử lý coding cho phép hiển thị thời tiết Bản đồ (WeatherMapsActivity): package com.tranduythanh.weatherprediction; import android.app.ProgressDialog; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; 10import com.google.android.gms.maps.SupportMapFragment; 11 import com.google.android.gms.maps.model.BitmapDescriptorFactory; 12import com.google.android.gms.maps.model.CameraPosition; 13import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; 14import com.google.android.gms.maps.model.MarkerOptions; 15import com.tranduythanh.utils.WeatherAsyncTask; 16 17public class WeatherMapsActivity extends FragmentActivity { 18 19private GoogleMap mMap; // Might be null if Google Play services APK is not 20available ProgressDialog myProgress; 21@Override 22protected void onCreate(Bundle savedInstanceState) { 23super.onCreate(savedInstanceState); 24setContentView(R.layout.activity_weather_maps); myProgress = new ProgressDialog(this); 25myProgress.setTitle("Đang tải Map "); 26myProgress.setMessage("Vui lòng chờ "); 27myProgress.setCancelable(true); //Hiển thị Progress Bar 28myProgress.show(); 29setUpMapIfNeeded(); 30addEvents(); 31} 32 /** 33* xử lý chọn địa điểm Map 34* lấy lớp LatLng để lấy kinh độ vĩ độ 35* truyền cho hàm moveAndShowWeatherNewPlace để hiển thị thời tiết địa 36điể 37*/ public void addEvents() 38{ 39if(mMap==null)return; 40mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { 41@Override void onMapClick(LatLng latLng) { 42public moveAndShowWeatherNewPlace(latLng); 43} 44}); 45} 46 47/** * hiển thị lại thời tiết địa điểm chọn đồ 48* @param latLng 49*/ 50private void moveAndShowWeatherNewPlace(LatLng latLng) { 51if (latLng != null) 52{ mMap.animateCamera(CameraUpdateFactory.newLatLngZoom( 53new LatLng(latLng.latitude, latLng.longitude), 13)); 54 55CameraPosition cameraPosition = new CameraPosition.Builder() // Sets the 56.target(new LatLng(latLng.latitude, latLng.longitude)) 57center of the map to location user // Sets the zoom 58.zoom(15) bearing(90) // Sets the orientation of the camera to east 59.tilt(40) // Sets the tilt of the camera to 30 degrees 60.build(); // Creates a CameraPosition from the builder 61mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 62 63MarkerOptions option=new MarkerOptions(); option.position(new LatLng(latLng.latitude, latLng.longitude)); 64option.title("Cho o cua tui").snippet("Tran Duy Thanh"); 65option.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory 66HUE_AZURE)); 67//option.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_tiempo) 68); //option.alpha(0.8f); 69//option.rotation(90); 70Marker maker = mMap.addMarker(option); 71//maker.showInfoWindow(); 72WeatherAsyncTask task=new 73WeatherAsyncTask(maker,mMap,WeatherMapsActivity.this,latLng.latitude,latLn g.longitude); 74task.execute(); 75//maker.showInfoWindow(); 76//mMap.setInfoWindowAdapter(new 77MyInfoWindowAdapter(maker,WeatherMapsActivity.this,lastLocation)); //tiến hành hiển thị lên Custom marker option lên Map: 78//maker.showInfoWindow(); 79} } 80 81@Override 82protected void onResume() { 83super.onResume(); 84//setUpMapIfNeeded(); } 85 86/** 87* Sets up the map if it is possible to so (i.e., the Google Play 88services APK is correctly 89* installed) and the map has not already been instantiated This will 90ensure that we only ever * call {@link #setUpMap()} once when {@link #mMap} is not null 91* <p/> 92* If it isn't installed {@link SupportMapFragment} (and 93* {@link com.google.android.gms.maps.MapView MapView}) will show a prompt 94for the user to the Google Play services APK on their device 95** install/update <p/> 96* A user can return to this FragmentActivity after following the prompt 97and correctly 98* installing/updating/enabling the Google Play services Since the 99FragmentActivity may not * have been completely destroyed during this process (it is likely that it 10would only be * stopped or paused), {@link #onCreate(Bundle)} may not be called again so 10we should call this * method in {@link #onResume()} to guarantee that it will be called 10*/ private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the 10map if (mMap == null) { 10// Try to obtain the map from the SupportMapFragment = ((SupportMapFragment) mMap getSupportFragmentManager().findFragmentById(R.id.map)) 10.getMap(); // Check if we were successful in obtaining the map 10if (mMap != null) { mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() { 10 @Override public void onMapLoaded() { 10//Đã tải thành công tắt Dialog Progress myProgress.dismiss(); 10} }); mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 11 mMap.getUiSettings().setZoomControlsEnabled(true); mMap.setMyLocationEnabled(true); 11 //setUpMap(); 11 TuiDangODau(); }} 11 } 11 /** * This is where we can add markers or lines, add listeners or move the camera In this case, we 11 * just add a marker near Africa * <p/> * This should only be called once and when we are sure that {@link #mMap} 11 is not null */ 11 private void setUpMap() { LatLng TTTH_KHTN = new LatLng(10.763181, 106.675664); MarkerOptions option=new MarkerOptions(); 11 option.position(TTTH_KHTN); option.title("Trung tâm tin học ĐH KHTN").snippet("Tran Duy Thanh"); 11 option.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory HUE_AZURE)); 12//option.alpha(0.8f); //option.rotation(90); Marker maker = mMap.addMarker(option); 12maker.showInfoWindow(); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(TTTH_KHTN, 15)); 12//mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker")); } 12 /** 12* mặc định lần đầu mở Map lên hiển thị chi tiết thời tiết vị trí 12* lên đồ */ private void TuiDangODau() { 12 LocationManager locationManager = (LocationManager) 12getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); 12 Location lastLocation = locationManager.getLastKnownLocation(locationManager.getBestProvider(crite 12ria, false)); if (lastLocation != null) 13{ mMap.animateCamera(CameraUpdateFactory.newLatLngZoom( 13new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()), 13)); CameraPosition cameraPosition = new CameraPosition.Builder() 13.target(new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude())) // Sets the center of the map to location user 13 // Sets the zoom zoom(15) bearing(90) // Sets the orientation of the camera to east 13.tilt(40) // Sets the tilt of the camera to 30 degrees build(); // Creates a CameraPosition from the builder 13mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 13MarkerOptions option=new MarkerOptions(); option.position(new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude())); 13option.title("Cho o cua tui").snippet("Tran Duy Thanh"); option.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory 13HUE_AZURE)); //option.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_tiempo) 13); //option.alpha(0.8f); //option.rotation(90); 14Marker maker = mMap.addMarker(option); //maker.showInfoWindow(); WeatherAsyncTask task=new 14WeatherAsyncTask(maker,mMap,WeatherMapsActivity.this,lastLocation.getLatit ude(),lastLocation.getLongitude()); task.execute(); 14//maker.showInfoWindow(); //mMap.setInfoWindowAdapter(new 14MyInfoWindowAdapter(maker,WeatherMapsActivity.this,lastLocation)); //tiến hành hiển thị lên Custom marker option lên Map: //maker.showInfoWindow(); 14} } 14} 14 14 14 14 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 17 17 17 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18 18 19 19 19 19 19 19 19 19 – Sau ta cần cấu hình AndroidManifest đầy đủ sau: 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 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tranduythanh.weatherprediction" > <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <!-The ACCESS_COARSE/FINE_LOCATION permissions are not required to use Google Maps Android API v2, but are recommended > <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="@string/google_maps_key" /> <activity 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 android:name=".WeatherMapsActivity" android:label="@string/title_activity_weather_maps" > </activity> <activity android:name=".WeatherCurrentLocationActivity" android:label="@string/title_activity_weather_current_location" > </activity> <activity android:name=".WeatherByAddressActivity" android:label="@string/title_activity_weather_by_address" > </activity> <activity android:name=".ChooseAddressActivity" android:label="@string/title_activity_choose_address" > </activity> </application> </manifest> – Như Tui trình bày gần hoàn chỉnh phần mềm xem dự báo thời tiết (còn chức dự báo ngày bạn tự làm) – Bạn cần đọc kỹ lại Map trước chưa rành, cố gắng đọc hiểu làm lại nhều lần – Các bạn tải source code đầy đủ (nhớ phải đổi lại KEY hoạt động phần Map): http://www.mediafire.com/download/3fwxcr8ziudjt47/WeatherPrediction.rar Nếu bạn muốn rèn luyện thêm lập trình Java, lập trình Android, lập trình Webservice với tổng thời lượng học >80 đăng ký học theo link sau: 1) Lập trình java tuần – 19 giờ(chỉ dành cho CHƯA BIẾT GÌ VỀ LẬP TRÌNH biết lơ mơ Java, lý thuyết tập phong phú tạo tảng lập trình Android hướng khác liên quan tới Java): https://kyna.vn/lap-trinh-java-trong-4-tuan/325931 2) Lập trình Android (>24 học) – toàn kiến thức Android bản: https://kyna.vn/lap-trinh-android-co-ban/325931 3) Lập trình Android nâng cao (23 học) – toàn kiến thức Android nâng cao: https://kyna.vn/lap-trinh-android-nang-cao/325931 4) Lập trình Webservice cho Di Động – 14 (dành cho ĐÃ BIẾT ANDROID), chưa biết Android tuyệt đối không đăng ký, khóa học hướng dẫn tỉ mỉ từ A->Z để xây dựng phần mềm hoàn chỉnh tương tác client-server: https://kyna.vn/lap-trinh-webservice-cho-di-dong/325931 – Chúc bạn thành công ... hình sử dụng phần mềm dự báo thời tiết sau: 1) Từ hình chính, bấm vào Thời tiết địa điểm thiết bị”: Chương trình hiển thị thông báo chi tiết dự báo thời tiết sau: Ta thấy chi tiết địa điểm thiết... (thời tiết địa điểm thiết bị, xem thời tiết theo địa điểm nhập xem thời tiết Google Map), chức dự báo ngày bạn tiếp tục thực Tui có cấu trúc tập tin, class dự án sau: – Tui chụp hình sử dụng phần. .. liên quan tới Du lịch, xem thời tiết Sau Coding chi tiết cho phần, tui giải thích đặc tính Android Studio, tương tự Eclipse (Tui trỏ link tới bạn đọc lại) Ta cần xây dựng mô hình class cho Weather

Ngày đăng: 09/08/2017, 07:20

Từ khóa liên quan

Mục lục

  • Xây dựng phần mềm dự báo thời tiết

Tài liệu cùng người dùng

Tài liệu liên quan