마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

구글 맵 지오코딩 및 위치마커에 대해서 질문드립니다.

0 추천

xml 파서를 통해서 위도 경도를 읽어오는데 까지는 성공했는데 이 위도, 경도를 통해 마커를 찍을 수 있는지 

질문드립니다... 

public class MainActivity extends FragmentActivity {
    /** Called when the activity is first created. */
 	
	String xml; //다운로드된 xml문서
 	GoogleMap TestMap;
	LatLng loc = new LatLng(35.5437482,129.2561333);
	double tmp,tmp2;
	 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	         
		StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
		.detectDiskReads()
		.detectDiskWrites()
		.detectNetwork()
		.penaltyLog()
		.build());
	        
		TestMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
		TestMap.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 15));
		TestMap.addMarker(new MarkerOptions().position(new LatLng(tmp,tmp2)).title("ㅋㅋ").snippet("ㅇㅇ"));
	}
	
    //버튼을 눌렀을때 실행되는 메소드 
    /* URL 인코딩 방법 예시
     * String URL = "www.myhome.com/";
	   String subURL = "한글값";
	   String thirdURL = "/index";

	   sbuURL =  URLEncoder.encode(subURL, "UTF-8");

	   URL = URL + subURL + thirdURL;
     */
    public void down(View v){
     StringBuffer sBuffer = new StringBuffer();
     try{
      String firstURL = "http://maps.googleapis.com/maps/api/geocode/xml?address=";
      String hangul = "63빌딩";
      String secondURL = "&sensor=true";
      String sbuURL =  URLEncoder.encode(hangul, "UTF-8");
           
      URL url = new URL(firstURL+sbuURL+secondURL);
      
      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
      if(conn != null){
       conn.setConnectTimeout(20000);
       conn.setUseCaches(false);
       if(conn.getResponseCode()==HttpURLConnection.HTTP_OK){
        //서버에서 읽어오기 위한 스트림 객체
        InputStreamReader isr = new InputStreamReader(conn.getInputStream());
        //줄단위로 읽어오기 위해 BufferReader로 감싼다.
        BufferedReader br = new BufferedReader(isr);
        
        //반복문 돌면서읽어오기
         while(true){
        	 String line = br.readLine();
         if(line==null){
          break;
         }
         sBuffer.append(line);
        }
        br.close();
        conn.disconnect();
       }
      }
      //결과값 출력해보기
      //editText.setText(sBuffer.toString());
      xml = sBuffer.toString(); //결과값 변수에 담기
     }catch (Exception e) {
   // TODO: handle exception
      Log.e("다운로드 중 에러 발생",e.getMessage());
      
  }
     parse();
     
}
    //xml파싱하는 메소드
    public void parse(){
     try{
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder documentBuilder = factory.newDocumentBuilder();
      
      //xml을 InputStream형태로 변환
      InputStream is = new ByteArrayInputStream(xml.getBytes());
      
      //document와 element 는 w3c dom에 있는것을 임포트 한다.
      Document doc = documentBuilder.parse(is);
      Element element = doc.getDocumentElement();
      
      //읽어올 태그명 정하기
      NodeList lats = element.getElementsByTagName("lat");
      NodeList lngs = element.getElementsByTagName("lng");
          
      //자료를 누적시킬 stringBuffer 객체
      StringBuffer sBuffer = new StringBuffer();

       Node item = lats.item(0);
       Node text = item.getFirstChild();
       Node item2 = lngs.item(0);
       Node text2 = item2.getFirstChild();
       
       //해당 노드에서 문자열 읽어오기
       String itemValue = text.getNodeValue();
       String itemValue2 = text2.getNodeValue();
      
       tmp = Double.parseDouble(itemValue);
       tmp2 = Double.parseDouble(itemValue2);
      
     }catch (Exception e) {
   // TODO: handle exception
      Log.e("파싱 중 에러 발생", e.getMessage());
     	}
    }
}

소스가 이런 형태로 되어 있는데

parse 메소드에서 받아온 String 형 위도(itemValue), 경도(ItemValue2)를 double형으로 변환(tmp,tmp2)한 뒤 마커에 찍

어주면 될 거같은데 이렇게 하니까 아무것도 표시가 안돼서...

조언 부탁드리겠습니다..

안드로이드!!!! (120 포인트) 님이 2014년 1월 17일 질문
안드로이드!!!!님이 2014년 1월 17일 수정
위경도를 정확히 읽어왔는지, 아무 위경도를 강제로 넣어도 표시가 되는지 확인해보셨나요?

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...