You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.7 KiB

using MapFinder.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
namespace MapFinder.Utility
{
static class KakaoAPI
{
internal static List<FoundLocale> Search(string query)
{
List<FoundLocale> localeList = new List<FoundLocale>();
string site = "https://dapi.kakao.com/v2/local/search/keyword.json";
string rquery = $"{site}?query={query}";
WebRequest request = WebRequest.Create(rquery);
string rkey = "69747398a2142e62bfdaefbab4adbc42"; // REST API KEY
string header = $"KakaoAK {rkey}";
request.Headers.Add("Authorization", header);
WebResponse response = request.GetResponse();
using (Stream resStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(resStream, Encoding.UTF8);
string json = reader.ReadToEnd();
dynamic dob = JsonConvert.DeserializeObject<dynamic>(json);
dynamic docs = dob["documents"];
JArray buff = docs;
int length = buff.Count;
for (int i = 0; i < length; i++)
{
string lname = docs[i]["place_name"];
double x = double.Parse(docs[i]["x"].ToString());
double y = double.Parse(docs[i]["y"].ToString());
localeList.Add(new FoundLocale(lname, x, y));
}
}
return localeList;
}
}
}