【ionic】ionicPopup.promptの入力フォームがキーボードで隠れないようにする
app.js
angular.module('starter', ['ionic']) .run(function($ionicPlatform, $localStorage, ParentService) { $ionicPlatform.ready(function() { if(window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false); // ★ここがデフォルトでtrueなのでfalseに! // cordova.plugins.Keyboard.disableScroll(true); cordova.plugins.Keyboard.disableScroll(false); } if(window.StatusBar) { StatusBar.styleDefault(); } });
これだけか。。以上です
緯度経度の2点間の距離、角度と座標 - GoogleMap
今回はapache cordovaのGoogleMapのプラグインの話だけど、GoogleMapのAPIならきっと同じように取得できると思われる。計算方法とか調べていたが実際にGoogleMapに表示してみるとけっこうずれたりしてうまくいかなかった。で、プラグインのドキュメント見てたらやりたいことがそのまま機能としてありました。。
GitHub - mapsplugin/cordova-plugin-googlemaps: Google Maps plugin for Cordova
GoogleMapの表示の方法は、READMEみればなんとなくわかるので書かない。
2点間の距離
var spherical = plugin.google.maps.geometry.spherical; var start = { lat: xxx.xxx, lng: xxx.xxx } var end = { lat: xxx.xxx, lng: xxx.xxx } var distance = spherical.computeDistanceBetween(start, end);
2点間の角度
var spherical = plugin.google.maps.geometry.spherical; var start = { lat: xxx.xxx, lng: xxx.xxx } var end = { lat: xxx.xxx, lng: xxx.xxx } var direction = spherical.computeHeading(start, end);
2点間上の任意の座標
var spherical = plugin.google.maps.geometry.spherical; var start = { lat: xxx.xxx, lng: xxx.xxx } var end = { lat: xxx.xxx, lng: xxx.xxx } var direction = spherical.computeHeading(start, end); var distance = xxx; nextLatLng = spherical.computeOffset(start, distance, direction);
GoogleMapすごい。以上です
【Go】Echo JsonにTemplateから生成したHTMLを埋め込んで返す
今回やりたかったことは以下。
・HTMLのテンプレートを変数等に定義しておく。
・テンプレートを元に動的な部分をHTMLに埋め込む。
・生成したHTMLをJSONにいれてレスポンスとして返す。
package main import( "net/http" "github.com/labstack/echo" ) // ViewData type ViewData struct { Title string `json:"id"` Contents string `json:"html"` } // レスポンスを表す構造体を定義 type JsonFormat struct { Id int `json:"id"` Html string `json:"name"` } func main() { e := echo.New() e.GET("/", func(c echo.Context) error { var buffer bytes.Buffer var html = "<div><h1>{{.Title}}</h1><p>{{.Contents}}</p></div>" var t = template.Must(template.New("html").Parse(html)) if err := t.Execute(&buffer, data); err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Server Error") } else { return c.JSON(http.StatusOK, Advertise { Id: 1, Html: buffer.String(), }) } }) }
以上です
glideでlogrusのインストールエラー対応
glideでgorm入れようとしたら突然logrusのエラーが。。。
[ERROR] Update failed for github.com/Sirupsen/logrus: The Remote does not match the VCS endpoint [ERROR] Could not update packages: The Remote does not match the VCS endpoint
意味わからんけど以下対応したら入った
$ rm -rf vendor $ rm -rf ~/.glide $ rm glide.lock
glide.yaml
github.com/sirupsen/logrus を github.com/Sirupsen/logrus に変更
で、以下を実行
$ glide get github.com/jinzhu/gorm
以上です
【Go】Echo アプリログ出力処理(複数ファイルへ)
実際使おうとすると調べる内容が細かい。。けどメモ。
logrusというのを使ってみる。ローテションはとりあえず考えない。
log/log.go
package log import ( "os" "fmt" "github.com/Sirupsen/logrus" ) var AppLog = logrus.New() var AppLog2 = logrus.New() func init() { // Log1 file, err := os.OpenFile("app.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { panic(fmt.Sprintf("[Error]: %s", err)) } AppLog.Out = file AppLog.Formatter = &logrus.JSONFormatter{} // Log2 file, err := os.OpenFile("app2.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { panic(fmt.Sprintf("[Error]: %s", err)) } AppLog2.Out = file AppLog2.Formatter = &logrus.JSONFormatter{} }
main.go
package main import ( "app/log" "github.com/labstack/echo" ) func main() { e := echo.New() log.AppLog.Info("Log1 Output") log.AppLog2.Info("Log2 Output") e.Start(":8080") }
以上です
【Go】Echo InternalServerErrorとNotFoundエラーを発生させる
こんなことできるのか
main.go
package main import ( "net/http" "github.com/labstack/echo" ) func main() { e := echo.New() e.GET("/users", func(c echo.Contet) error { // エラーを返す return echo.NewHTTPError(http.StatusInternalServerError, "Server Error") // return echo.NewHTTPError(http.StatusNotFound, "Not Found") }) e.Start(":8080") }
以上です