2017-03-01 178 views
-1

我想通過使用發送位置功能將固定在單個地圖上的多個位置發送到telegram-bot。有沒有辦法將多個位置發送到電報機器人?我嘗試只能發送一個位置到電報機器人。如何通過Telegram Bot在Google地圖上添加多個地點?

+3

也許您可以提供您當前的代碼,顯示您如何發送單個位置。然後顯示您已經嘗試發送多個位置的內容,以及輸出的內容。 – feedMe

+0

我發送我的發送請求代碼像這樣 「await Bot.SendLocationAsync(message.Chat.Id,43.296482,5.369763);」 但我想發送長和經緯度列表在地圖上顯示 –

+0

請閱讀此http://stackoverflow.com/help/how-to-ask – feedMe

回答

1

據我所知,你想發送多個位置給用戶,所以你不想把數字放在SendLocation方法中。如果需要發送的位置是一些固定的位置,您可以將它們保存在數組或數據庫中,並使用循環發送它們。

但如果他們不固定,你必須將它們先發送機器人,然後強制機器人發送給用戶或其他任何地方(通道或一組),下面的代碼可以幫助你:

//Send the location like: latitude=xxx&longtitude=yyy; 
if(update.Message.Text.Contains("latitude") && update.Message.Text.Contains("longtitude")) 
{ 
string latitude = text.Split('&').First(); 
string longtitude = text.Split('&').Last(); 
//splites the input text into two parts first part is latitude=xxx and second or last part is longtitude=yyy. because the string is splited based on & sign 

float latitue_num = float.Parse(latitude.Split('=').Last()); 
float longtitude_num = float.Parse(longtitude.Split('=').Last()); 
//does the same action for "latitude=xxx" and "longtitude=yyy" after that the number xxx is stored in latitude_num and yyy is stored in longtitude_num 

var req = new SendLocation(update.Message.Chat.Id, latitue_num, longtitude_num); 
await bot.MakeRequestAsync(req); 
} 

當然,如果位置數量太大,最好使用數據庫並將它們從數據庫發送到機器人。

如果你想從一個用戶的位置發送給機器人(而不是從機器人到用戶),您可以使用:

if(update.Message.Location != null) 
{ 
. 
. 
. 
//here you can do whatever you want every time bot receives a location. no matter how many locations are sent to the bot the bot will receive them one by one and do the action(s) listed in this method. 
} 

我希望這會幫助你,你的問題並不清楚,因此我這樣解釋。

+0

謝謝你從你的答案,但我的問題是關於在單個地圖發送多個位置。我通過發送來自地圖的照片解決了我的問題,該地圖從此網址創建谷歌地圖https://maps.googleapis.com/maps/api/staticmap?center=tehran,ir&zoom=13&size=600x300&maptype=roadmap&markers=color:blue%7Clabel: S%7C40.702147,-74.015794&markers = color = green:green%7Clabel:G%7C40.711614,-74.&markers = color = red%7Clabel:C%7C40.718217,-73.998284&key = AIzaSyC1iKAPcxTPoTFzRcIlJjw9Qj-NSSokipE –

+0

@fatememosleh This can這是一個好主意,但這樣對你的機器人用戶來說很難,因爲你只發送照片,而不是地圖或位置。 [此鏈接](https://www.create.net/support/218-how-to-pin-point-multiple-locations-on-google-maps.html)也可能對您有所幫助。按照鏈接中的步驟進行操作後,您可以輕鬆地在電報機器人中發送地圖鏈接。你可以用自己喜歡的名字命名你自己的地圖並在其上標上多個位置。 –

相關問題