Skip to content

Instantly share code, notes, and snippets.

@Kento-E

Kento-E/appsscript.json

Last active Dec 11, 2018
Embed
What would you like to do?
Hangouts Chatbot: getting lat, lng & address.
{
"timeZone": "Asia/Tokyo",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"chat": {
}
}
function onAddToSpace(event) {
if (event.space.type == "DM") {
var name = event.user.displayName;
return {
text: "@" + name +
" さん、追加ありがとうございます。場所の名前を入力してみてください。"
};
} else {
return {
text: event.space.displayName + "への追加ありがとうございます。場所の名前を入力してみてください。"
}
}
}
function onMessage(event) {
// Creates a new Geocoder object.
var geocoder = Maps.newGeocoder();
// Creates a Geocoder with the language set to Japanese.
geocoder = geocoder.setLanguage('ja');
// Creates a Geocoder with the region set to Japan.
// geocoder = Maps.newGeocoder().setRegion('ja');
var msg = event.message.argumentText;
// Delete Spaces
msg = msg.replace(/ /g, '');
var response = geocoder.geocode(msg);
for (var i = 0; i < response.results.length; i++) {
var result = response.results[i];
}
if (result){
return {
text: "住所: " + result.formatted_address
+ "\n" + "緯度: " + result.geometry.location.lat
+ "\n" + "経度: " + result.geometry.location.lng
+ "\n" + "URL: https://www.google.co.jp/maps/search/" + msg + "/"
};
// 絵文字が含まれる場合はそのまま返す
} else if(msg.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)) {
return {
text: msg
}
} else {
return {
text: "結果が出力できませんでした。 \n 入力内容をお確かめの上、再度入力してください。"
};
}
}
function onRemoveFromSpace(event) {
return {
text: "退出します。"
};
}
function onCardClick(event) {
return {
text: "カードがクリックされました。"
};
}
@Kento-E

This comment has been minimized.

Copy link
Owner Author

@Kento-E Kento-E commented Oct 30, 2018

latlng01
latlng02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment