Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 하루 한마디 영어
- 안드로이드 배경화면
- 안드로이드 2.0 개발
- 구글 안드로이드 개발
- 아이폰 배경화면
- SKY 시리우스
- 스마트폰 배경화면
- android
- 아이폰 바탕화면
- 구글 안드로이드
- 안드로이드 바탕화면
- 안드로이드 개발 2.0 강좌
- 스카이 안드로이드폰 시리우스
- 인기있는 블로그 만들기
- 안드로이드 개발
- 안드로이드 개발 2.0
- 안드로이드2.0개발
- 스카이 안드로이드폰 시리우스 K양 동영상
- sky 시리우스폰
- 안드로이드 개발 강좌
- 안드로이드2.0
- 안드로이드
- 안드로이드개발
- Form Stuff
- MapView
- 안드로이드폰
- objective-c
- 하루한마디영어
- 구글안드로이드
- 영어
Archives
- Today
- Total
moozi
11/25 cookmap 본문
package com.cookandroid.cookmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.GroundOverlayOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
GoogleMap gMap;
MapFragment mapFrag;
GroundOverlayOptions videoMark, videoMark2;//maker출력에 사용
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//fragment 찾기
//mapFrag=(MapFragment)getFragmentManager().findFragmentById(R.id.map);
// mapFrag.getMapAsync(this);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
///// (1) Bus Route ID /////
String serviceUrl = "http://ws.bus.go.kr/api/rest/busRouteInfo/getBusRouteList";
String serviceKey = "발급받은키";
// serviceKey = URLEncoder.encode(serviceKey);
String strSrch = "406";
String strUrl = serviceUrl+"?ServiceKey="+serviceKey+"&strSrch="+strSrch;
DownloadWebpageTask1 task1 = new DownloadWebpageTask1();
task1.execute(strUrl);
/*
gMap=googleMap;
gMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);//인공위성지도
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.568256,126.897240),15));
//마커생성
videoMark=new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.presence_video_busy)).position(new LatLng(37.568256,126.897240),100f,100f);
//맵에 마커올리기
gMap.addGroundOverlay(videoMark);
videoMark2=new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.presence_video_busy)).position(new LatLng(37.232323,126.787878),100f,100f);
gMap.addGroundOverlay(videoMark2);
gMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
//마커생성
videoMark=new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.presence_video_busy)).position(latLng,100f,100f);
//맵에 마커올리기
gMap.addGroundOverlay(videoMark);
}
});
*/
}
private class DownloadWebpageTask1 extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
try {
return (String)downloadUrl((String)urls[0]);
} catch (IOException e) {
return "다운로드실패";
}
}
protected void onPostExecute(String result) {
String headerCd = "";
String busRouteId = "";
String busRouteNm = "";
boolean bSet_headerCd = false;
boolean bSet_busRouteId = false;
boolean bSet_busRouteNm = false;
///// (1) Bus Route ID /////
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(result));
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
;
} else if(eventType == XmlPullParser.START_TAG) {
String tag_name = xpp.getName();
if (tag_name.equals("headerCd"))
bSet_headerCd = true;
if (tag_name.equals("busRouteId"))
bSet_busRouteId = true;
if (tag_name.equals("busRouteNm"))
bSet_busRouteNm = true;
} else if(eventType == XmlPullParser.TEXT) {
if (bSet_headerCd) {
headerCd = xpp.getText();
bSet_headerCd = false;
}
if (headerCd.equals("0")) {
if (bSet_busRouteId) {
busRouteId = xpp.getText();
bSet_busRouteId = false;
}
if (bSet_busRouteNm) {
busRouteNm = xpp.getText();
bSet_busRouteNm = false;
}
}
} else if(eventType == XmlPullParser.END_TAG) {
;
}
eventType = xpp.next();
}
} catch (Exception e) {
}
///// (2) Bus Position /////
String serviceUrl = "http://ws.bus.go.kr/api/rest/buspos/getBusPosByRtid";
String serviceKey = "발급받은키2";
String strUrl = serviceUrl+"?ServiceKey="+serviceKey+"&busRouteId="+busRouteId;
DownloadWebpageTask2 task2 = new DownloadWebpageTask2();
task2.execute(strUrl);
}
private String downloadUrl(String myurl) throws IOException {
HttpURLConnection conn = null;
try {
URL url = new URL(myurl);
conn = (HttpURLConnection) url.openConnection();
BufferedInputStream buf = new BufferedInputStream(conn.getInputStream());
BufferedReader bufreader = new BufferedReader(new InputStreamReader(buf, "utf-8"));
String line = null;
String page = "";
while((line = bufreader.readLine()) != null) {
page += line;
}
return page;
} finally {
conn.disconnect();
}
}
}
private class DownloadWebpageTask2 extends DownloadWebpageTask1 {
protected void onPostExecute(String result) {
String headerCd = "";
String plainNo = "";
String gpsX = "";
String gpsY = "";
boolean bSet_headerCd = false;
boolean bSet_gpsX = false;
boolean bSet_gpsY = false;
boolean bSet_plainNo = false;
///// (2) Bus Positions
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(result));
int eventType = xpp.getEventType();
int count = 0;
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
;
} else if (eventType == XmlPullParser.START_TAG) {
String tag_name = xpp.getName();
if (tag_name.equals("headerCd"))
bSet_headerCd = true;
if (tag_name.equals("gpsX"))
bSet_gpsX = true;
if (tag_name.equals("gpsY"))
bSet_gpsY = true;
if (tag_name.equals("plainNo"))
bSet_plainNo = true;
} else if (eventType == XmlPullParser.TEXT) {
if (bSet_headerCd) {
headerCd = xpp.getText();
bSet_headerCd = false;
}
if (headerCd.equals("0")) {
if (bSet_gpsX) {
count++;
gpsX = xpp.getText();
bSet_gpsX = false;
}
if (bSet_gpsY) {
gpsY = xpp.getText();
bSet_gpsY = false;
}
if (bSet_plainNo) {
plainNo = xpp.getText();
bSet_plainNo = false;
//구글맵에 위치 표시
displayBus(gpsX, gpsY, plainNo);
}
}
} else if (eventType == XmlPullParser.END_TAG) {
;
}
eventType = xpp.next();
}
} catch (Exception e) {
}
}
private void displayBus(String gpsX, String gpsY, String plainNo) {
double latitude;
double longitude;
LatLng LOC;
latitude = Double.parseDouble(gpsY);
longitude = Double.parseDouble(gpsX);
LOC = new LatLng(latitude, longitude);
Marker mk1 = mMap.addMarker(new MarkerOptions()
.position(LOC)
.title(plainNo)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.bus)));
mMap.moveCamera(CameraUpdateFactory.newLatLng(LOC));
mMap.moveCamera(CameraUpdateFactory.zoomTo(11));
}
}
}
'TIS_2018 > 응용sw2018_2기' 카테고리의 다른 글
jsoup 사용하기 (0) | 2018.11.27 |
---|---|
11/26 member.jsp (0) | 2018.11.26 |
11/21 DBListView (0) | 2018.11.22 |
안드로이드연습문제07 (0) | 2018.11.21 |
11/21 DB ListView (0) | 2018.11.21 |
Comments