-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.sai.servlet; | ||
|
||
import java.net.URLEncoder; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
|
||
import org.json.simple.JSONObject; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
public class SearchLastSubPath { | ||
|
||
static String shortT, minT, shtStateName, minStateName; | ||
|
||
static public JSONObject findPath(String sub) { | ||
|
||
String lastSub = sub; | ||
String shtState = ""; | ||
|
||
JSONObject result = new JSONObject(); | ||
|
||
for(int i = 0; i < SearchTenSub.friends.length; i++) { | ||
|
||
try { | ||
String url = "http://swopenapi.seoul.go.kr/api/subway/sample/xml/shortestRoute/0/1/"; | ||
String fURL = URLEncoder.encode(SearchTenSub.friends[i], "UTF-8"); | ||
String sURL = URLEncoder.encode(lastSub, "UTF-8"); | ||
String pathURL = url + fURL + "/" + sURL; | ||
|
||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder builder = factory.newDocumentBuilder(); | ||
Document document = builder.parse(pathURL); | ||
|
||
document.getDocumentElement().normalize(); | ||
|
||
NodeList shortList = document.getElementsByTagName("row"); | ||
|
||
//소요시간 구하는 식 | ||
for(int k = 0; k < shortList.getLength(); k++){ | ||
Node nNode = shortList.item(k); | ||
if(nNode.getNodeType() == Node.ELEMENT_NODE){ | ||
|
||
Element eElement = (Element) nNode; | ||
|
||
NodeList shtStatnId = eElement.getElementsByTagName("shtStatnId").item(0).getChildNodes(); | ||
Node shtStatnIdInfo = (Node) shtStatnId.item(0); | ||
shtState = shtStatnIdInfo.getNodeValue(); | ||
|
||
NodeList shtStatnNm = eElement.getElementsByTagName("shtStatnNm").item(0).getChildNodes(); | ||
Node shtStatnNmInfo = (Node) shtStatnNm.item(0); | ||
shtStateName = shtStatnNmInfo.getNodeValue(); | ||
|
||
NodeList minStatnId = eElement.getElementsByTagName("minStatnId").item(0).getChildNodes(); | ||
Node minStatnIdInfo = (Node) minStatnId.item(0); | ||
String minState = minStatnIdInfo.getNodeValue(); | ||
|
||
NodeList minStatnNm = eElement.getElementsByTagName("minStatnNm").item(0).getChildNodes(); | ||
Node minStatnNmInfo = (Node) minStatnNm.item(0); | ||
minStateName = minStatnNmInfo.getNodeValue(); | ||
|
||
NodeList shtTravelTm = eElement.getElementsByTagName("shtTravelTm").item(0).getChildNodes(); | ||
Node shtTrabelInfo = (Node) shtTravelTm.item(0); | ||
shortT = shtTrabelInfo.getNodeValue(); | ||
|
||
NodeList minTravelTm = eElement.getElementsByTagName("minTravelTm").item(0).getChildNodes(); | ||
Node minTravelTmInfo = (Node) minTravelTm.item(0); | ||
minT = minTravelTmInfo.getNodeValue(); | ||
|
||
} | ||
|
||
} | ||
|
||
JSONObject res = new JSONObject(); | ||
|
||
res = MakePathToJson.makeJson(shtState); | ||
res.put("shtTravelTm", shortT); | ||
res.put("minTravelTm", minT); | ||
|
||
String key = SearchTenSub.friends[i]; | ||
result.put(key, res); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.sai.servlet; | ||
|
||
import java.awt.Image; | ||
import java.awt.Toolkit; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
|
||
import org.json.simple.JSONObject; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
public class SearchMiddlePlace { | ||
|
||
public static JSONObject getHotPlace() { | ||
|
||
JSONObject place = new JSONObject(); | ||
|
||
try { | ||
|
||
String url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/locationBasedList?ServiceKey=LzJ73NnpJ9i8FwimSqcbaJpLp6x9nN4TCDnDBSPhf8TEA05I5fi6G%2FIhjRdbQcD5FZ%2FH778Vpm4vE%2F9OTB6D6Q%3D%3D&mapX=" | ||
+ MakePathToJson.mapX + "&mapY=" + MakePathToJson.mapY + "&radius=1000&listYN=Y&arrange=A&MobileOS=ETC&MobileApp=AppTest&arrange=B"; | ||
|
||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder parser = factory.newDocumentBuilder(); | ||
Document doc = parser.parse(url); | ||
Element eRoot = doc.getDocumentElement(); | ||
|
||
System.out.println(eRoot.getTagName()); | ||
|
||
NodeList items = doc.getElementsByTagName("item"); | ||
|
||
for(int i = 0; i < items.getLength(); i++) { | ||
Node itemNode = items.item(i); | ||
|
||
Element itemElmnt = (Element)itemNode; | ||
|
||
NodeList addr1 = itemElmnt.getElementsByTagName("addr1").item(0).getChildNodes(); | ||
Node addr1Info = (Node) addr1.item(0); | ||
String add1 = addr1Info.getNodeValue(); | ||
|
||
NodeList firstImage = itemElmnt.getElementsByTagName("firstimage").item(0).getChildNodes(); | ||
Node firstImageInfo = (Node) firstImage.item(0); | ||
String firstIm = firstImageInfo.getNodeValue(); | ||
Image image = Toolkit.getDefaultToolkit().getImage(firstIm); | ||
|
||
NodeList readcount = itemElmnt.getElementsByTagName("readcount").item(0).getChildNodes(); | ||
Node readcountInfo = (Node) readcount.item(0); | ||
String read = readcountInfo.getNodeValue(); | ||
|
||
if(itemElmnt.getElementsByTagName("title").item(0).getChildNodes().getLength() != 0) { | ||
NodeList title = itemElmnt.getElementsByTagName("title").item(0).getChildNodes(); | ||
Node titleInfo = (Node) title.item(0); | ||
String title1 = titleInfo.getNodeValue(); | ||
|
||
System.out.println("이름: " + title1); | ||
} | ||
|
||
if(itemElmnt.getElementsByTagName("tel").item(0).getChildNodes().getLength() != 0) { | ||
NodeList tel = itemElmnt.getElementsByTagName("tel").item(0).getChildNodes(); | ||
Node telInfo = (Node) tel.item(0); | ||
String tele = telInfo.getNodeValue(); | ||
|
||
System.out.println("전화번호: " + tele); | ||
} | ||
|
||
System.out.println("이미지: " + image); | ||
System.out.println("위치: " + add1); | ||
System.out.println("조회수: " + read); | ||
|
||
System.out.println("----------------------------------------------"); | ||
|
||
} | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(System.err); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.sai.servlet; | ||
|
||
import java.awt.geom.Point2D; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.ArrayList; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
import org.json.simple.parser.ParseException; | ||
|
||
import com.sai.dao.MemberDAO; | ||
|
||
public class SearchMiddlePoint implements Action { | ||
|
||
/* 프론트에서 넘어오는 인원 수 파악해서 동적으로 배열 생성해야하며, 넘어오는 데이터로 디비에 접근해서 좌표 가져와야 함. | ||
* 좌표를 가져와서 xList, yList에 동적으로 넣어야 함. | ||
*/ | ||
public static String[] friends; //넘어온 인원 수 파악해서 동적으로 크기 지정, friends에는 알고리즘에 참여한 사람들의 역이 들어가야함. | ||
double[] xList; | ||
double[] yList; | ||
|
||
@Override | ||
public String execute(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
Point2D.Double mCenterPoint = null; | ||
ArrayList<Point2D> mVertexs = new ArrayList<Point2D>(); | ||
|
||
System.out.println("중간 지점 찾기 페이지 연결"); | ||
|
||
String sData = request.getParameter("data"); | ||
System.out.println("sData의 내용 : " + sData); | ||
|
||
JSONParser jsonParser = new JSONParser(); | ||
JSONObject jsonObject = new JSONObject(); | ||
|
||
try { | ||
jsonObject = (JSONObject) jsonParser.parse(sData); | ||
|
||
System.out.println("jsonObject의 내용은 : " + jsonObject); | ||
|
||
// friends = new String[memberList.size()]; | ||
|
||
JSONArray stationInfoList = (JSONArray) jsonObject.get("stationList"); | ||
|
||
System.out.println("stationInfoList의 사이즈는 : " + stationInfoList.size()); | ||
|
||
xList = new double[stationInfoList.size()]; | ||
yList = new double[stationInfoList.size()]; | ||
|
||
for(int i = 0; i < stationInfoList.size(); i++) { | ||
JSONObject list = (JSONObject) stationInfoList.get(i); | ||
String stationName = (String) list.get("stationName"); | ||
Double mapX = Double.parseDouble(list.get("mapX").toString()); | ||
Double mapY = Double.parseDouble(list.get("mapY").toString()); | ||
|
||
mVertexs.add(new Point2D.Double(mapX, mapY)); | ||
|
||
} | ||
|
||
} catch (ParseException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
if (mCenterPoint != null) | ||
System.out.println("mCenterPoint != null"); | ||
|
||
double centerX = 0.0, centerY = 0.0; | ||
double area = 0.0; | ||
|
||
mCenterPoint = new Point2D.Double(0.0, 0.0); | ||
int firstIndex, secondIndex, sizeOfVertexs = mVertexs.size(); | ||
|
||
Point2D.Double firstPoint; | ||
Point2D.Double secondPoint; | ||
|
||
double factor = 0.0; | ||
|
||
for (firstIndex = 0; firstIndex < sizeOfVertexs; firstIndex++) { | ||
secondIndex = (firstIndex + 1) % sizeOfVertexs; | ||
|
||
firstPoint = (java.awt.geom.Point2D.Double) mVertexs.get(firstIndex); | ||
secondPoint = (java.awt.geom.Point2D.Double) mVertexs.get(secondIndex); | ||
|
||
factor = ((firstPoint.getX() * secondPoint.getY()) - (secondPoint.getX() * firstPoint.getY())); | ||
|
||
area += factor; | ||
|
||
centerX += (firstPoint.getX() + secondPoint.getX()) * factor; | ||
centerY += (firstPoint.getY() + secondPoint.getY()) * factor; | ||
} | ||
|
||
area /= 2.0; | ||
area *= 6.0f; | ||
|
||
factor = 1 / area; | ||
|
||
centerX *= factor; | ||
centerY *= factor; | ||
|
||
System.out.println("centerX : " + centerX); | ||
System.out.println("centerY : " + centerY); | ||
|
||
mCenterPoint.setLocation(centerX, centerY); | ||
System.out.println("출력 : " + mCenterPoint.toString()); | ||
|
||
|
||
System.out.println("중간 지점의 midX : " + mCenterPoint.getX()); | ||
System.out.println("중간 지점의 midY : " + mCenterPoint.getY()); | ||
System.out.print("면적 : " + area); | ||
|
||
JSONObject result = new JSONObject(); | ||
|
||
result = SearchTenSub.search(mCenterPoint.getX(), mCenterPoint.getY()); | ||
|
||
PrintWriter out = response.getWriter(); | ||
out.println(result); | ||
|
||
return null; //반환 페이지 | ||
|
||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.sai.servlet; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
|
||
import org.json.simple.JSONObject; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
public class SearchTenSub { | ||
|
||
static String statName[] = new String[10]; | ||
//friends배열에는 지하철역명이 들어가야함. | ||
static String friends[] = new String[3]; //동적으로 생성해야함. | ||
static String lastSub = ""; | ||
|
||
public static JSONObject search(double mapX, double mapY) { | ||
|
||
JSONObject result = new JSONObject(); | ||
JSONObject place = new JSONObject(); | ||
|
||
try{ | ||
|
||
String locURL = "http://swopenapi.seoul.go.kr/api/subway/5947735178616c77393747474d664c/xml/nearBy/0/10/" + mapX + "/" + mapY; | ||
|
||
DocumentBuilderFactory dbFactoty = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder dBuilder = dbFactoty.newDocumentBuilder(); | ||
Document doc = dBuilder.parse(locURL); | ||
|
||
doc.getDocumentElement().normalize(); | ||
|
||
NodeList nList = doc.getElementsByTagName("row"); | ||
|
||
for(int i = 0; i < nList.getLength(); i++){ | ||
Node nNode = nList.item(i); | ||
if(nNode.getNodeType() == Node.ELEMENT_NODE){ | ||
|
||
Element eElement = (Element) nNode; | ||
|
||
NodeList statnNm = eElement.getElementsByTagName("statnNm").item(0).getChildNodes(); | ||
Node statnNmInfo = (Node) statnNm.item(0); | ||
String state = statnNmInfo.getNodeValue(); | ||
|
||
NodeList subwayNm = eElement.getElementsByTagName("subwayNm").item(0).getChildNodes(); | ||
Node subwayNmInfo = (Node) subwayNm.item(0); | ||
String subway = subwayNmInfo.getNodeValue(); | ||
|
||
NodeList subwayXcnts = eElement.getElementsByTagName("subwayXcnts").item(0).getChildNodes(); | ||
Node subwayXcntsInfo = (Node) subwayXcnts.item(0); | ||
String subwayX = subwayXcntsInfo.getNodeValue(); | ||
|
||
NodeList subwayYcnts = eElement.getElementsByTagName("subwayYcnts").item(0).getChildNodes(); | ||
Node subwayYcntsInfo = (Node) subwayYcnts.item(0); | ||
String subwayY = subwayYcntsInfo.getNodeValue(); | ||
|
||
//역 10개 배열에 삽입 | ||
statName[i] = state; | ||
} | ||
} | ||
|
||
lastSub = ChooseLastSub.getTotalTime(); | ||
result = SearchLastSubPath.findPath(lastSub); | ||
|
||
System.out.println(result); | ||
|
||
place = SearchMiddlePlace.getHotPlace(); | ||
|
||
} catch (Exception e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
return result; //!결과값이랑 플레이스 목록이 같이 리턴되어야 함. | ||
} | ||
} |