• Manifest 추가

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  • java 코드

      /** 
       * LatLng 기반으로 주소를 확인 
       * @param mContext : Geocoder에 전달하기 위한 context 
       * @param latlng : GPS Latitude, longitude 
       */ 
      public static void getLocation(Context mContext, LatLng latlng){ 
          Geocoder geocoder = new Geocoder(mContext); 
          try { 
              // latitude : the latitude a point for the search
              // longitude : the longitude a point for the search
              // maxResults : max number of addresses to return. Smaller numbers (1 to 5) are recommended 
              List<Address> mListAddress = geocoder.getFromLocation(latlng.latitude, latlng.longitude, 5); 
              for(int i=0; i<mListAddress.size(); i++){ 
                  Log.e("GPS_Info", " " + i + " : "  + mListAddress.get(i).toString()); 
              } 
          } catch (IOException e) { 
              e.printStackTrace(); 
          } 
      }
  • LatLng(37.151984, 126.844849)의 Log 결과

    0 : Address[addressLines=[0:"대한민국 경기도 화성시 팔탄면 노하리 1224-8"],feature=1224−8,admin=경기도,sub-admin=null,locality=화성시,thoroughfare=팔탄면,postalCode=445-910,countryCode=KR,countryName=대한민국,hasLatitude=true,latitude=37.151984,hasLongitude=true,longitude=126.84484989999999,phone=null,url=null,extras=null] 
    1 : Address[addressLines=[0:"대한민국 경기도 화성시 팔탄면 노하리"],feature=445-909,admin=경기도,sub-admin=null,locality=화성시,thoroughfare=팔탄면,postalCode=445-909,countryCode=KR,countryName=대한민국,hasLatitude=true,latitude=37.1550957,hasLongitude=true,longitude=126.8546282,phone=null,url=null,extras=null] 
    2 : Address[addressLines=[0:"대한민국 경기도 화성시 팔탄면 노하리"],feature=노하리,admin=경기도,sub-admin=null,locality=화성시,thoroughfare=팔탄면,postalCode=445-910,countryCode=KR,countryName=대한민국,hasLatitude=true,latitude=37.1545293,hasLongitude=true,longitude=126.85712099999999,phone=null,url=null,extras=null] 
    3 : Address[addressLines=[0:"대한민국 경기도 화성시 팔탄면"],feature=팔탄면,admin=경기도,sub-admin=null,locality=화성시,thoroughfare=팔탄면,postalCode=445-910,countryCode=KR,countryName=대한민국,hasLatitude=true,latitude=37.161111999999996,hasLongitude=true,longitude=126.9032039,phone=null,url=null,extras=null] 
    4 : Address[addressLines=[0:"대한민국 경기도 화성시"],feature=화성시,admin=경기도,sub-admin=null,locality=화성시,thoroughfare=null,postalCode=null,countryCode=KR,countryName=대한민국,hasLatitude=true,latitude=37.1994932,hasLongitude=true,longitude=126.8311887,phone=null,url=null,extras=null] 
    5 : Address[addressLines=[0:"대한민국 경기도"],feature=경기도,admin=경기도,sub-admin=null,locality=null,thoroughfare=null,postalCode=null,countryCode=KR,countryName=대한민국,hasLatitude=true,latitude=37.413799999999995,hasLongitude=true,longitude=127.5183,phone=null,url=null,extras=null]
    6 : Address[addressLines=[0:"대한민국"],feature=대한민국,admin=null,sub-admin=null,locality=null,thoroughfare=null,postalCode=null,countryCode=KR,countryName=대한민국,hasLatitude=true,latitude=35.907757,hasLongitude=true,longitude=127.76692200000001,phone=null,url=null,extras=null]

    GPS주소가 정확히 건물 위치가 아닌 도로한가운데를 가르킨다. Return 되는 address들은 정확히 도로명을 나타내기 보다는
    주변에 등록된 가까운 주소를 반환하는 것 같다.
    Address 0,1,2 는 그 위치에서 가까운 주소를 반환
    Address 3 은 뒤에 자세한 주소를 생략하고 ' ~면 ' 까지만 반환
    Address 4 는 ' ~시 ' 까지만 반환
    Address 5 는 ' ~도 ' 까지만 반환
    Address 6 는 국가 까지만 반환

    실제 구글지도에서 Lat, Lng 찍은 값과 다른 주소값이 리턴되기 때문에 정확한 주소를 다 사용하기 보다는
    Address 0,1,2의 thoroughfare 데이터까지만 사용하면 될것 같다.

https://www.everdevel.com/PHP/post-get.php

 

everdevel

웹 입문 사이트 에버디벨 - HTML, CSS, JavaScript, jQuery, MySQL ,PHP를 다룹니다.

www.everdevel.com

 

https://ppost.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-PHP-%EC%97%B0%EB%8F%99-%EC%98%88%EC%A0%9C-%EC%84%A4%EB%AA%85

'리눅스 > 데이터베이스' 카테고리의 다른 글

mysql과 통신을 위한 php 서버  (0) 2019.07.11
Ubuntu에서 mysql 명령어 사용  (0) 2019.07.11

*php 서버 위치 :

$cd /var/www/htrml

*파일 권한설정 755

$ sudo chmod 755 -R ./*

try.php

localhost : 로컬호스트, 일반적으로 로컬호스트 고정
root : mysql의 user
mysql : 패스워드
testdb : root 계정에 존재하는 databasae 이름

<?php  

$link=mysqli_connect("localhost", "root", "mysql", "testdb");  
if (!$link)
{  
    echo "MySQL 접속 에러 : ";
    echo mysqli_connect_error();
    exit();  
}  

mysqli_set_charset($link,"utf8"); 


$sql="select * from solar";

$result=mysqli_query($link,$sql);
$data = array();   
if($result){  

    while($row=mysqli_fetch_array($result)){
        array_push($data, 
            array('id'=>$row[0]
        ));
    }

    header('Content-Type: application/json; charset=utf8');
$json = json_encode(array("webnautes"=>$data), JSON_PRETTY_PRINT+JSON_UNESCAPED_UNICODE);
echo $json;

}  
else{  
    echo "SQL문 처리중 에러 발생 : "; 
    echo mysqli_error($link);
} 



mysqli_close($link);  

?>

insert.php

dbcon.php의 연결을 이어받아서 insert 명령어를 수행한다.

<?php 

    error_reporting(E_ALL); 
    ini_set('display_errors',1); 

    include('dbcon.php');


    if( ($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['submit']))
    {

        $name=$_POST['name'];
        $country=$_POST['country'];

        if(empty($name)){
            $errMSG = "이름을 입력하세요.";
        }
        else if(empty($country)){
            $errMSG = "나라를 입력하세요.";
        }

        if(!isset($errMSG))
        {
            try{
                $stmt = $con->prepare('INSERT INTO person(name, country) VALUES(:name, :country)');
                $stmt->bindParam(':name', $name);
                $stmt->bindParam(':country', $country);

                if($stmt->execute())
                {
                    $successMSG = "새로운 사용자를 추가했습니다.";
                }
                else
                {
                    $errMSG = "사용자 추가 에러";
                }

            } catch(PDOException $e) {
                die("Database error: " . $e->getMessage()); 
            }
        }

    }
?>

<html>
   <body>
        <?php 
        if (isset($errMSG)) echo $errMSG;
        if (isset($successMSG)) echo $successMSG;
        ?>

        <form action="<?php $_PHP_SELF ?>" method="POST">
            Name: <input type = "text" name = "name" />
            Country: <input type = "text" name = "country" />
            <input type = "submit" name = "submit" />
        </form>

   </body>
</html>

<?php 
    }
?>

dbcon.php

<?php
    $host = 'localhost';
    $username = 'root'; # MySQL 계정 아이디
    $password = 'mysql'; # MySQL 계정 패스워드
    $dbname = 'testdb';  # DATABASE 이름


    $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');

    try {

        $con = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8",$username, $password);
    } catch(PDOException $e) {

        die("Failed to connect to the database: " . $e->getMessage()); 
    }


    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $con->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

    if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { 
        function undo_magic_quotes_gpc(&$array) { 
            foreach($array as &$value) { 
                if(is_array($value)) { 
                    undo_magic_quotes_gpc($value); 
                } 
                else { 
                    $value = stripslashes($value); 
                } 
            } 
        } 

        undo_magic_quotes_gpc($_POST); 
        undo_magic_quotes_gpc($_GET); 
        undo_magic_quotes_gpc($_COOKIE); 
    } 

    header('Content-Type: text/html; charset=utf-8'); 
    #session_start();
?>

참고
[1] https://webnautes.tistory.com/828
[2] https://yoo-hyeok.tistory.com/17?category=708422

'리눅스 > 데이터베이스' 카테고리의 다른 글

PHP 서버 설정  (0) 2019.07.11
Ubuntu에서 mysql 명령어 사용  (0) 2019.07.11

mysql 설치

$ sudo apt-get install mysql;

myhsql 실행

mysql에 등록한 user 이름과 password를 기입한다.

    $ mysql -u user - p
    Enter password :

database 보기

기존에 만들어진 데이터베이스 목록을 보여준다.
만약 기존에 만든 db가 없으면 새로 db를 만들어 준다.

mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| information\_schema |  
| testdb              |
+---------------------+

해당 database 확인

만들어진 db를 선택한다.

mysql> use testdb;
Database changed;

db의 table 보기

db에서 만들어진 table 목록을 확인한다.
table이 없으면 만들어야 한다.

mysql> show tables;  

+--------------------+  
| Tables_in_testdb   |  
+--------------------+
| person             |
+--------------------+

table의 내용 보기

testdb에 person이란 table이 있으면 이 person 테이블을 선택한다.

mysql> select \* from person;  
+---------------------+  
| id | name | country |  
+---------------------+
|  1 | test | kr      |  
|  2 | test | uk      |  
+---------------------+

'리눅스 > 데이터베이스' 카테고리의 다른 글

PHP 서버 설정  (0) 2019.07.11
mysql과 통신을 위한 php 서버  (0) 2019.07.11

참고

[1] https://heropy.blog/2017/09/30/markdown/

[PHP서버 설정] https://webnautes.tistory.com/828

[PHP서버 설정2] http://blog.naver.com/PostView.nhn?blogId=phj8498&logNo=221346945899

1. .bashrc 편집하기

$ cd ~/
$ vi .bashrc

2. 파일 리스트 출력 예약어 등록

alias ll='ls -lsa'

3. 상위 디렉터리 이동 예약어 등록

alias u='cd ..'

4. scp 예약어 등록

alias scptest='scp test.txt root@192.168.1.1:/opt:'

5. .bashrc 저장

ESC키 입력  
:wq + Enter  

'리눅스 > 기타' 카테고리의 다른 글

리눅스 7z 압축풀기  (0) 2019.07.08
ARM 기반 소프트웨어 효율성 증대  (0) 2016.03.09
MCU 선정, Cortex 시리즈, 보드 선정  (0) 2016.03.09
bash shell  (0) 2016.01.25

1. 패키지 설치

$ sudo apt-get install p7zip-full

2. 압축 해제하기

  • 명령어 7z, 옵션 x

    $ 7z x 파일이름.7z
  • 예제

    $ 7z x text.7z

'리눅스 > 기타' 카테고리의 다른 글

.bashrc에서 예약어 등록하기  (0) 2019.07.08
ARM 기반 소프트웨어 효율성 증대  (0) 2016.03.09
MCU 선정, Cortex 시리즈, 보드 선정  (0) 2016.03.09
bash shell  (0) 2016.01.25

+ Recent posts