티스토리가 1월 21일 부터 모든 블로그에 SSL이 적용되었다.

더 안전한 블로그 활동을 위해 - SSL 전면 적용


블로그로 접속하면 http에서 https로 변경된 것을 볼 수 있다. 



브라우저에서 위와 같은 표시가 나타나면서 안전하지 않은 콘텐츠가 차단됨 메시지가 나타났다.




현재 사용하고 있는 스킨이 Flatinum 스킨인데 이 스킨내부에서 http를 사용하는 부분이 있어서 다른 스킨으로 변경 했다. 




Letter 반응형 스킨으로 변경 한 후 적용해보니 해당 오류가 사라졌다.  기존에 썼던 스킨이 좀더 나았던거같은데 좀 아쉽긴하다 ..


추가로 기존에 스킨에서 http로 요청하는 부분을 https로 변경하는 방법이 있다. 

해당 링크 참초 : https://dololak.tistory.com/580

블로그 이미지

클라인STR

,
geolocation 을 이용하여 현재 위치 (위도, 경도를 구하는 코드이다.) 해당코드를 이용하여 위도, 경도 위치 정보를 파라메터로 하여 API를 호출하는 서비스를 개발하는 중인데 비동기 호출때문에 문제가 됬다. 

1
2
3
4
5
6
7
8
9
10
11
12
  navigator.geolocation.getCurrentPosition(
       (position) => {
        this.setState({
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          error: null,
        })
        
      },
      (error) => this.setState({ error: error.message }),
      { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 },

    );

cs

[기존에 썼던 코드]



1
2
3
4
5
6
7
8
9
10
11
12
13
var getPosition = function (options) {
  return new Promise(function (resolve, reject) {
    navigator.geolocation.getCurrentPosition(resolve, reject, options);
  });
}
 
getPosition()
  .then((position) => {
    console.log(position);
  })
  .catch((err) => {
    console.error(err.message);
  });

cs

[변경될 형태의 코드]



참고 

https://gist.github.com/varmais/74586ec1854fe288d393

https://stackoverflow.com/questions/47544564/how-geolocation-getcurrentposition-return-value


블로그 이미지

클라인STR

,


react-native-circular-progress  바로가기



react-native-svg 가 먼저 설치되어 있어야 한다. 


react-native-svg 설치하기  바로가기



npm i --save react-native-circular-progress    




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { AnimatedCircularProgress } from 'react-native-circular-progress';
 
 . . .
 
 
render() {
 
    return (
      <View style={{flex:1, justifyContent:"center", alignItems:"center"}}>
            <AnimatedCircularProgress
            size={200}
            width={15}
            fill={100}
            tintColor="#00e0ff"
            onAnimationComplete={() => console.log('onAnimationComplete')}
            backgroundColor="#3d5875" />
        </View>
    );
 
  }
 
cs




블로그 이미지

클라인STR

,

위도 경도 좌표변환에 대해서 알아 보는중 통계청 지리정보 서비스를 발견하게 되었다. 


SGIS PLUS 개발지원센터



회원가입 신청 버튼을 선택한다. 



Chrome 브라우저에서 회원가입 신청링크로 접속이 되지않아서 이후에 진행은 IE브라우저에서 진행하였다. 




스크롤을 내력서 사용약관을 읽고 정책 동의를 모두 체크한다음 회원가입 버튼을 선택한다. 



필수입력항목을 입력하고 회원가입 버튼을 선택한다. 



인증키 발급 신청을 선택한다. 



API 약관을 읽고 동의 버튼을 선택한다.



인증키 신청내역중 필수입력항목을 빠짐없이 입력하고 신청 버튼을 클릭한다.



https://sgis.kostat.go.kr/developer/html/openApi/app/myApp.html 마이페이지 접속하면 현재 신청된 인증키 를 확인할 수 있다. 

서비스ID , 보안Key를 실제 API 신청시 사용한다. 

블로그 이미지

클라인STR

,

React Native 위도 경도 구하기  바로가기


이전 포스팅에서 위도 , 경도를 구한 값을 TM좌표로 변환해보기로한다. 

TM좌표로 변환하기위해서는 통계청 SGIS API를 이용한다. 


  API를 사용하기위해서는 인증단계를 먼저 거쳐야한다. 응답정보 값인 accessToken 값이 필요하다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const API_AUTH = "https://sgisapi.kostat.go.kr/OpenAPI3/auth/authentication.json";
 
const CONSUMER_KEY = ""//Service ID
const CONSUMER_SECRET = ""//서비스 Secret
 
 
function fetchAuth(latitude, longitude) {
    let url = `${API_AUTH}?consumer_key=${CONSUMER_KEY}&consumer_secret=${CONSUMER_SECRET}`;
    console.log(url);
    fetch(url)
        .then(response => response.json())
        .then(data => {
            console.log("fetchAuth Result");
            console.log(data);
            fetchCrdTms(data.result.accessToken, latitude, longitude);  
        })
        .catch(error => {
            console.log("error");
            console.log(error);
        });
}
cs


fetchAuth 함수를 하나 생성하여 인증 accessToken을 요청한다. 



인증 요청결과 Json Data 형식





좌표변환 API는 위와 같은요청형식을 사용한다. 

src는 현재 좌표체계 값이고 dst는 변경하고자하는 좌표 체계의 값이다. 


위도 경도를 구한 좌표값은 WGS84(World Geodetic System) 형식이다. 좌표계코드표를 참고를 선택하면 아래와 같이 팝업이 호출된다.




공공데이터 포털 API중 환국환경공단에서 사용하는 좌표계는 중부원점이다. 

공공데이터 포털 Q&A 좌표계변환 문의 참고링크



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const API_TRAD = "https://sgisapi.kostat.go.kr/OpenAPI3/transformation/transcoord.json";
const WGS84 = 4326//WGS84 경/위도
const GRS80 = 5181//GRS80 중부원점

function fetchCrdTms(accessToken, latitude, longitude) {
    //x축이 longtitude 경도 y축이 latitude 위도 
    let url = `${API_TRAD}?accessToken=${accessToken}&src=${WGS84}&dst=${GRS80}&posX=${longitude}&posY=${latitude}`;
    console.log(url);
    fetch(url)
    .then(response => response.json())
    .then(data => {
        console.log("fetchCrdTms Result");
        console.log(data);
      
    })
    .catch(error => {
        console.log("error");
        console.log(error);
    });
}
cs





블로그 이미지

클라인STR

,




MapTest 프로젝트 api 호출 테스트중 Network request failed 에러가 나면서 해당 API가 호출되지않는 현상이 발생하였다.



Xcode 열어서 info.plist 파일을 위와 같이 수정하고 다시 테스트 해보았다. 해당옵션 추가시 정상적으로 호출되었다. 

혹시 나 동일현상이 일어나는경우를 대비해서 해당 내용을 기록함 


Network request failed 관련 참고 URL


https://stackoverflow.com/questions/30720813/cfnetwork-sslhandshake-failed-ios-9?fbclid=IwAR0-0G1dVomWFV091WZz6XYqkY7h1TfVwduWk1NED915GTjF-AhGk54GYdk

https://www.facebook.com/groups/reactapp/search/?query=Network%20request%20failed&epa=SEARCH_BOX

https://www.youtube.com/watch?v=iZpI-jqvs18

https://www.youtube.com/watch?v=shstJgkLW-I

https://github.com/facebook/react-native/issues/16081

https://stackoverflow.com/questions/38418998/react-native-fetch-network-request-failed

https://stackoverflow.com/questions/30720813/cfnetwork-sslhandshake-failed-ios-9?fbclid=IwAR0-0G1dVomWFV091WZz6XYqkY7h1TfVwduWk1NED915GTjF-AhGk54GYdk

iOS 9 / OS X 10.11 앱 네트워크 보안 정책


블로그 이미지

클라인STR

,



연관포스팅 링크 바로가기


iOS Simulator 실행한다. 




Simulator -> Debug -> Location -> Custom Location 선택한다.



위도와 경도에 값을 원하는 값으로 설정하고 OK 버튼을 선택한다음 다시 테스트 코드를 실행한다. 



설정한 Location 으로 값이 변경된걸 확인할 수 있다. 




원하는 장소에 위도와 경도를 가장 쉽게아는 방법은 구글지도를 이용하는 것이다. 


구글지도를 접속한다.



지도검색란에 주소를 입력한다.




지도 위치꼭지란을 클릭하고 이곳이 궁금한가요? 클릭한다. 




웹브라우저 하단에 위도, 경도가 숫자로 표시된다. 


참고 

https://stackoverflow.com/questions/42377279/react-native-i-cant-find-my-current-locationgeolocation-ios

https://stackoverflow.com/questions/52430007/xcode-10-ios-12-simulator-location-simulation-fails-on-city-bicycle-ride-city

블로그 이미지

클라인STR

,

IOS인 경우 react-native init 통해서 프로젝트를 생성한경우 info.plist에 필요한 키가 설정되어있다. (NSLocationWhenInUseUsageDescription)


geolocation api는 navigator.geolocation 통해 액세스 한다.



geolocation.getCurrentPosition(geo_success, [geo_error], [geo_options]);


getCurrentPostion 함수는 파라메터로 성공콜백, 실패콜백, Option Object 세가지 매개변수를 허용한다.

성공콜백은 아래와 같은 object 객체를 전달한다. 


1
2
3
4
5
6
7
8
9
10
11
12
{
  "timestamp"1484669056399.49,
  "coords": {
    "accuracy"5,
    "altitude"0,
    "altitudeAccuracy"-1,
    "heading"-1,
    "latitude"37.785834,
    "longitude"-122.406417,
    "speed"-1
  }
}
cs


오류콜백은 에러메시지를 전달한다. Option Object는 enableHighAccuracy (boolean), timeout (milliseconds), maximumAge (milliseconds) 구성되어있다.


timeout : api 요청시 timeout 값 설정한다. (응답반응할수 있는 최대 허용시간 Default INFINITY)

enableHighAccuracy : GPS를 사용할지 여부를 나타낸다. 

maximumAge : 반환된 값의 최대 보존기간을 설정한다.  (Default INFINITY) 0으로 설정하면 장치가 캐시된 위치를 사용할 수 없다. Default 값을 INFINITY 설정하면 항상 캐싱된 값을 반환한다.




1
2
3
4
5
6
7
8
9
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
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
export default class App extends Component {
  
  constructor(props) {
    super(props);
    this.state = {
      latitude: null,
      longitude: null,
      error: null,
    };
  }
  componentDidMount() {
    navigator.geolocation.getCurrentPosition(
      (position) => {
        this.setState({
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          error: null,
        });
      },
      (error) => this.setState({ error: error.message }),
      { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 },
    );
  }
  render() {
    return (
      <View style={{ flexGrow: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Latitude: {this.state.latitude}</Text>
        <Text>Longitude: {this.state.longitude}</Text>
        {this.state.error ? <Text>Error: {this.state.error}</Text> : null}
      </View>
    );
  }
}
 
cs




latitude : 위도이고 , longitude 경도를 나타낸다.


출처  

https://facebook.github.io/react-native/docs/geolocation#getcurrentposition

https://hackernoon.com/react-native-basics-geolocation-adf3c0d10112

https://medium.com/@icodeinswift/location-permissions-in-ios-apps-always-or-when-in-use-371c1b22e02e

https://medium.com/@icodeinswift/location-permissions-in-ios-apps-always-or-when-in-use-371c1b22e02e


블로그 이미지

클라인STR

,