2017-10-24 3 views
1

Microsoft botフレームワークを使用してチャットボットを作成しています。私は "アクティビティ"から緯度と経度の値を取得する方法に固執しています。BotFrameworkを使用してChatBotユーザーの緯度と経度を取得する方法

「アクティビティ」から緯度と経度の情報を取得する方法はありますか?

すでにここにはsimilar questionが存在しますが、この質問に対する回答はありません。

私はMicrosoft..Bot.Builder.Locationを試しましたが、それはユーザーの寛大さと長さを与えるものではありませんが、ユーザーからの情報の取得と検証に役立ちます。

ご迷惑をおかけして申し訳ございません。

+0

どのチャンネルを使用しますか? –

+0

ボットフレームワークエミュレータとフェイスブック –

答えて

3

あなたは場所の緯度と経度を取得するには、この無料のREST APIを使用することができ、このREST APIには、Wi-FiをTraingulationに取り組んでいます。

REST API for getting Latitude and Longitude of a place

REST APIの出力に対応したモデルクラスは、直列化復元に使用してください:

public class PlaceGeography 
     { 
      public string ip { get; set; } 
      public string country_code { get; set; } 
      public string country_name { get; set; } 
      public string region_code { get; set; } 
      public string region_name { get; set; } 
      public string city { get; set; } 
      public string zip_code { get; set; } 
      public string time_zone { get; set; } 
      public float latitude { get; set; } 
      public float longitude { get; set; } 
      public int metro_code { get; set; } 
     } 

を、単にボットフレームワークであなたのC#コードからGETリクエストを作成し、同様になりますこれは

public async static Task<HttpResponseMessage> GetCoOrdinates() 
     { 
      string responseJSON = string.Empty; 
      PlaceGeography obj = new PlaceGeography(); 

      using (HttpClient client = new HttpClient()) 
      { 
       string URI = $"http://freegeoip.net/json/"; 
       client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 

       using (HttpResponseMessage msg = await client.GetAsync(URI)) 
       { 
        if (msg.IsSuccessStatusCode) //if HTTP 200 then 
        { 
         responseJSON = await msg.Content.ReadAsStringAsync(); 
         JsonConvert.PopulateObject(responseJSON, obj); // Deserialize model class object and get latitude and longitude 
         return msg; 
        } 
        else 
         return msg; 
       } 

      } 
     } 
1

携帯電話のメッセンジャーの場合、ユーザーは組み込み機能を使用して自分の位置情報を送信できます。彼らはそれを行うならば、あなたは、着信メッセージから値を受け取ることができます。

var location = activity.Entities?.FirstOrDefault(e => e.Type == "Place"); 

if (location != null) 
{ 
    var latitude = location.Properties["geo"]?["latitude"]?.ToString(); 
    var longitude = location.Properties["geo"]?["longitude"]?.ToString(); 
} 
関連する問題