2015年7月31日 星期五

Android Google map 現在位置 到 點擊 marker 距離 寫法

float distance = 0;
先取得現在位置的經緯度
Location crntLocation = new Location("");
crntLocation.setLatitude(latitude);
crntLocation.setLongitude(longitude);

在取得點擊 marker 的經緯度
Location newLocation = new Location(""); newLocation.setLatitude(latitude2); newLocation.setLongitude(longitude2);
distance = crntLocation.distanceTo(newLocation); // in mdistance = distance / 1000;//km

String km =  new DecimalFormat("0.0").format(distance);



2015年7月30日 星期四

eclipse pakeage 轉android studio vpon無法執行問題

eclipse  轉 android studio
vpon  會無法編輯 問解決
因為在libs資料夾已經找不到vpon.jar了

先將jar 複製 libs 資料夾內














之後選取 add as library 




重新編譯完就可以使用了



2015年7月29日 星期三

如何使用WebView 呼叫本地端的html

1.先將要使用的html 資料放到 assets










語法如下

WebView aboutweb = (WebView) findViewById(R.id.mwebview_about);
WebSettings webViewSettings = aboutweb.getSettings();
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setDomStorageEnabled(true);
webViewSettings.setDatabaseEnabled(true);
aboutweb.loadUrl("file:///android_asset/about/about.html");


file:///android_asset/about/about.html
意思是 asset 底下的 about 資料夾 裡面的about.html檔案

2015年7月28日 星期二

地址轉成經緯度 畫在地圖上方法 Geocoder Marker Googlemap

 程式碼如下:



Geocoder geoCoder = new Geocoder(MainActivity.this, Locale.getDefault());

                    List<Address> addressLocation = geoCoder.getFromLocationName(store_add, 1);
                    if(addressLocation.size()<=0){
                        double latitude = 34.058621;
                        double longitude =-118.246938;
                        Log.d("Jack", String.valueOf(latitude) + "," + String.valueOf(longitude));
                        MarkerOptions mo2 = new MarkerOptions();
                        mo2.position(new LatLng(latitude, longitude))

                                .snippet("")
                                .title("")
                                .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_live));
                        Marker marker2 = mMap.addMarker(mo2);
                        mMarkers.add(marker2);



                    }else{

                        double latitude = addressLocation.get(0).getLatitude();
                        double longitude = addressLocation.get(0).getLongitude();
                        Log.d("Jack", String.valueOf(latitude) + "," + String.valueOf(longitude));
                        MarkerOptions mo = new MarkerOptions();
                        mo.position(new LatLng(latitude, longitude))

                                .snippet(zone)
                                .title(store)
                                .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_live));
                        Marker marker = mMap.addMarker(mo);
                        mMarkers.add(marker);


                    }

store_add  是 String  看你要給一個地址  給使用者輸入地址 或者爬Json 的地址
                  都可以放到這個值
 
 1               是 要回傳幾筆資料  這邊建議  輸入1  就好


     if(addressLocation.size()<=0)   會用迴圈 是因為 可以取的地址會無法轉成經緯度

所以用迴圈去判斷 取的是否小於0這個值

 double latitude = addressLocation.get(0).getLatitude();
 double longitude = addressLocation.get(0).getLongitude();


這就是為什麼要去用迴圈做判斷的原因

因為用Geocoder 地址轉經緯度  拿到的值可能不只一個 所以要用最相近的值
所以才要 .get(0)

之後取出來 就可以畫在google map 上了
                        MarkerOptions mo = new MarkerOptions();
                        mo.position(new LatLng(latitude, longitude))

                                .snippet(zone)
                                .title(store)
                                .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_live));
                        Marker marker = mMap.addMarker(mo);
                        mMarkers.add(marker);

2015年7月23日 星期四

Android xml background 透明度 設定方法

假如 透明度20% 該怎麼設定了

很簡單

先開啟小算盤

檢視 開啟 程式設計師

100% 在16進位 等於FF
轉換成10進位 等於 255

20% =  255 *20 /100 = 51.

在轉換 16進位 等於 33 

把在這個值 加到最前面就可以囉

EX:

 android:background="#33....."