2014年11月11日 星期二

[Android] 百度地圖-更改中心點與Zoom

              記得加入百度地圖SDK,


            程式碼內容
                 LatLng point = new LatLng(30.245324, 130.123541);
// 在地图上添加Marker,并显示
marker = (Marker) (mBaiduMap.addOverlay(option));
// BaiduMap Location 改變地圖中心點
MapStatus mMapStatus = new MapStatus.Builder().target(point).zoom(17).build();
// 定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory
.newMapStatus(mMapStatus);
// 改变地图状态
mBaiduMap.setMapStatus(mMapStatusUpdate);


參考網址
http://tieba.baidu.com/p/2263186672

[Android] 百度地圖 在地圖上畫圈圈


記得把百度的SDK放進lib裡

//畫圓圈圈
OverlayOptions polygonOption = new CircleOptions()
.center(Point).radius(Round)
.fillColor(ColorRound)
.stroke(new Stroke(5, ColorStroke));

mBaiduMap.addOverlay(polygonOption);

參考資料
http://blog.csdn.net/xiyushiyi/article/details/38360305

[Android] 百度地圖 經緯度 轉 地址

轉百度經緯度方法如下

百度地图SDK采用的是百度自有的地理坐标系(bdll09),因此开发者在做位置标注的时候,需要将其他类型的坐标转换为百度坐标。相应的接口和转换方式如下:

//將谷歌地圖,搜搜地圖,阿里雲地圖,mapabc地圖和地圖AMAP//所用坐標轉換成百度坐標
CoordinateConverter轉換器=新CoordinateConverter();
converter.from(CoordType.COMMON);
// sourceLatLng待轉換坐標
converter.coord(sourceLatLng);
經緯度desLatLng= converter.convert();

//將GPS設備採集的原始GPS坐標轉換成百度坐標
CoordinateConverter轉換器=新CoordinateConverter();
converter.from(CoordType.GPS);
// sourceLatLng待轉換坐標
converter.coord(sourceLatLng);
經緯度desLatLng= converter.convert();

參考位置:http://developer.baidu.com/map/index.php?title=androidsdk/guide/tool


如此function ,把轉換好的經緯度貼呼叫好貼上即可

private String getBaibuAddress(final double StationLatitude, final double StationLongitude) {

GeoCoder coder = GeoCoder.newInstance();

ReverseGeoCodeOption reverseCode = new ReverseGeoCodeOption();
ReverseGeoCodeOption result = reverseCode.location(new LatLng(
StationLatitude, StationLongitude));
coder.reverseGeoCode(result);
coder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {

@Override
public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
String Address = result.getAddress();
}

@Override
public void onGetGeoCodeResult(GeoCodeResult result) {
String Address = result.getAddress();
}
});

return null;
}


2014年10月20日 星期一

[Android] 字符串分割--java中String.split()用法

        比較常看到的都是一個一個解開,最近看到有比較好的解法
       
         由於有參考網址,所以就不多做解釋了。

                需求
                       得到Type後的數值與Account後的數值,

                字串內容
                        Type=5,Account=352151022027333
     
                程式碼
      String TN[] = new String[2];
        Type_Name = description;
        String[] TypeName = Type_Name.split("[,=]+");

        for(int i=0 ; i < TypeName.length ; i++){
        Type = Integer.valueOf(TypeName[1]);
        DeviceAccount = TypeName[3];
        }

1
2
3
4
5
6
7
 private String[] EcName(String splitSymbol, String splitString){
          String[] StringName = splitString.split("[" + splitSymbol + "]+");
          for(int i=0 ; i < StringName.length ; i++){
           System.out.println("StringName..." + StringName[i]);
          }
  return StringName;
 }

參考網址
http://www.inote.tw/java-split-string-to-array

[Android] 打包簽署 APK 時出現 Export aborted because fatal lint errors were found 錯誤

http://marcoyan0814.blogspot.tw/2014/04/android-apk.html

[Android] 分解JSON的資料

解JSON!!!解JSON!!!解JSON!!!解JSON!!!解JSON!!!解JSON!!!解JSON!!!
JSONArray是 "[" ,JSONOject是"{"


JSON 內容 - 1
[{"station":[{"longitude":116.346596,"latitude":39.930893,"radius":78}],
   "mark":[{"longitude":"116.346346","latitude":"39.930990"}],
   "data":[{"name":"张智隆","location_type":"0",
                "location":"北京市西城区百万庄南街10号院-5号楼","event":"用戶即時定位",
                "type":"26","watch_time":"2014-11-12 08:47",
                "server_time":"2014-11-12 08:48"}],
   "status":"0","msg":"2800"}]

程式碼內容 - 1
String Station = new JSONArray(data).getJSONObject(0).getString("station");
String Mark = new JSONArray(data).getJSONObject(0).getString("mark");
String Data = new JSONArray(data).getJSONObject(0).getString("data");
//Station
StationLatitude = new JSONArray(Station).getJSONObject(0).getDouble("latitude");
StationLongitude = new JSONArray(Station).getJSONObject(0).getDouble("longitude");
StationRadius = new JSONArray(Station).getJSONObject(0).getInt("radius");
//Mark
String MarkLatitude = new JSONArray(Mark).getJSONObject(0).getString("latitude");
String MarkLongitude = new JSONArray(Mark).getJSONObject(0).getString("longitude");
//Data
DataName = new JSONArray(Data).getJSONObject(0).getString("name");
DataLocationType = new JSONArray(Data).getJSONObject(0).getInt("location_type");
String DataLocation = new JSONArray(Data).getJSONObject(0).getString("location");
DataEvent = new JSONArray(Data).getJSONObject(0).getString("event");
String DataType = new JSONArray(Data).getJSONObject(0).getString("type");
DataWatchTime = new JSONArray(Data).getJSONObject(0).getString("watch_time");
DataServerTime = new JSONArray(Data).getJSONObject(0).getString("server_time");


抓取JSON裡的內容多少,還沒用過,不確定
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   JSONArray arr = new JSONArray(postResult); JSONObject obj = arr.getJSONObject(0); // Db.getInstance(this).deleteMsgSafeData(null); if(obj.optString("status").equals("0")){ arr = obj.getJSONArray("data"); for(int i=0; i<arr.length(); i++){ JSONObject msg = arr.getJSONObject(i); MessageSafe msgData = new MessageSafe(); msgData.setUserAccount(data.getUser_account());
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

參考網址
http://dean-android.blogspot.tw/2013/06/androidjson.html

2014年9月18日 星期四

[Android] 自動生成的技巧

呼!!~~自己摸索找了兩個方法可以讓城市來自己自動生成,我們常常在程式裡面看到很多的
// TODO Auto-generated method stub
什麼之類的...這些都自己生成的,如果說是向生命週期的那種,那就不用多說了!
相信已經很多人都用過了。(這方法我也找了很久,就讓我囉嗦一下吧!!)
好吧!!~切入正題!!~

方法一
程式代碼
public class MainActivity extends ActionBarActivity{

private Button btn1;
private TextView txt1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //這裡下面兩行一樣
        btn1=(Button)findViewById(R.id.Button1);
        txt1=(TextView)findViewById(R.id.textView1);
        //這裡開始 開始一直打
        //btn1.setOnClickListener(new 
        //打到這裡開始 alt+/ 點選第一個 就會下面全跑出來了
        btn1.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
                                 txt1.setText("wow");
}
       
        });
    }
}





方法二       適合團隊撰寫
程式代碼
public class MainActivity extends ActionBarActivity{

private Button btn1;
private TextView txt1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn1=(Button)findViewById(R.id.Button1);
        txt1=(TextView)findViewById(R.id.textView1);
        //這裡的話就要注意了,雖然可以先打
        //但是主要就是下面的function還沒有打出來
        //所以就算是先打出來了,後面的空格裡也會沒有function可以加
        //所以這裡建議是在下面的function打出來之後在來打就好了
        txt3.setOnClickListener(btnClick);

    }
       //再來這裡的話也是一樣打
       //private View.OnClickListener btnClick = new
       //就到這裡後面的話都是alt+/ 選擇第一個
       //後面就會自己生成了
       // 在來就可以打上面的txt3.setOnClickListener(
       //然後在選擇下面所命名的名稱就可以了
    private View.OnClickListener btnClick = new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

}
};
     }
}




感謝大家的收看!!!希望對一些剛開始學android開發的新手會有幫助!~~