728x90

private val groupList: Unit
    private get() {
        remoteService = RetrofitAPI.getClient().create(RemoteService::class.java)
        val groupResultCall = remoteService?.getGroupList(Value.encrypt(Value.URLkey()))
        groupResultCall?.enqueue(object : Callback<GroupResult> {
            override fun onResponse(call: Call<GroupResult>, response: Response<GroupResult>) {
                if (response.body()!!.status.contains("success")) {
                    groupItem.clear()
                    val groupData = response.body()!!.message
                    for (item in groupData) {
                        groupItem.add(item)
                    }
                    Log.d("TAG", "Number of groupItem :" + groupItem.size)
                }
            }

            override fun onFailure(call: Call<GroupResult>,t: Throwable) {
            }
        })
    }
 


Java로 작성한 코드를 코틀린으로 변환하여 테스트하고 적어둔다.


override fun onClick(view: View) {
    when (view.id) {
        R.id.btn_drawer -> drawer_layout.openDrawer(GravityCompat.START)
        R.id.btn_group -> {
            // 팝업 메뉴 나오게 하는 방법
            Log.d("TAG", "popupMenu of groupItem :" + groupItem.size)
            val popupMenu = PopupMenu(this, view)
            val menu = popupMenu.menu
            var i = 0
            while (i < groupItem.size) {
                menu.add(Menu.NONE,i,Menu.NONE,groupItem[i].name)
                i++
            }
            popupMenu.setOnMenuItemClickListener { item: MenuItem ->
                val i = item.itemId
                freeActiveMarkers()
                getAddrData(item.title.toString())
                LocationAt(groupItem[i].latitude.toDouble(),groupItem[i].longitude.toDouble())
                Toast.makeText(context,item.title.toString() + " 선택했습니다",Toast.LENGTH_SHORT).show()
                true
            }
            popupMenu.show()
        }
    }
}


private fun LocationAt(latitude: Double, longitude: Double) {
    val coord = LatLng(latitude, longitude)
    mNaverMap!!.moveCamera(CameraUpdate.scrollTo(coord).animate(CameraAnimation.Easing, 300))
}


PHP 서버코드

<?php
error_reporting(0);
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
header("Cache-Control: no-cache, must-revalidate");
header("Content-type: application/json; charset=utf-8");

// 파일을 직접 실행하는 비정상적 동작을 방지 하기 위한 목적
if(isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST"){
    @extract($_POST);
    require_once 'path.php';// root 폴더를 기준으로 상대적인 경로 자동 구하기
    require_once $g['path_config'].'config.php';
    require_once $g['path_class'].'dbconnect.php';
    require_once $g['path_class'].'loginClass.php';
    $c = new LoginClass;

    //키워드 확인
    if(!isset($_POST['keyword'])){
        $result = array(
            'status' => "fail",
            'message' => "no keyword"
        );
        echo json_encode($result);
        exit;
    }

    $keyword=$c->AES_Decode($_POST['keyword']);
    //키워드 일치 확인
    if(strcmp($keyword,$mykey)<>0){
        $result = array(
            'status' => "keyfail",
            'message' => "서버와 단말의 KEY가 일치하지 않습니다."
        );
        echo json_encode($result);
        exit;
    }

    // 배열 저장
    $R = array();
    array_push($R,array("name"=>"전체","latitude"=>"37.358752","longitude"=>"127.1149243"));
    $map_sql = "select name,latitude,longitude from mapTree";
    $map_result = mysqli_query($db,$map_sql);
    while($row = mysqli_fetch_row($map_result)) {
        array_push($R,array("name"=>$row[0],"latitude"=>$row[1],"longitude"=>$row[2]));
    }

    $status = "success";
    $message = $R;
   
    $result = array(
        'status' => $status,
        'message' => $message
    );
    echo json_encode($result);
}
?> 


728x90
블로그 이미지

Link2Me

,