After switching from Wordpress to Jekyll I got a lot faster load times. But I also got to type more to get a post published. This can be eased by using snippets in the Atom editor in which i write my posts.
A snippet is a small region of code that you use often. In Atom and many other editors these can be inserted by typing a few words and then let the editor fill in the rest by pushing tab.
Jekyll example
In Jekyll you start all posts with defining a few variables in front matter. This posts front matter look like this:
Instead of typing that every time I create a post I can create a snippet that automatically finishes all that text after i type --- and push tab.
Creating a snippet in Atom
Open up the snippets.cson file by clicking Atom->Snippets... in the menu.
Atom snippets menu
Now type snip and push tab to get a scaffold for creating your own snippet. When first pushing tab this is what we’ll get:
the .source.js is setting in which files the snippet will be active. In this case javascript files.
‘Snippet Name’ is the name of the snippet.
Prefix is what will trigger the snippet.
Body is what the trigger will be replaced with.
This is an example of a snippet that works in markdown files to add front matter variables:
A snippet with tab stops
In this blog i also use a lot of code highlighting. To highlight code with Jekyll you type something like this:
instead of always adding a javascript snippet i can add a tab stop to this snippet so that i always get to type what language i am highlighting. That snippet would look like this:
When I used the Ionic CLI to create the Dogwalk project it came with an iOS project. Now it’s time to add the Android platform.
These are the steps i took to install the Android SDK and add the Android Platform. I ran into errors, maybe you’ll get them as well, so even though this was not a smooth install maybe it helps!
Ionic add platform Android
To add the android platform to your app you run the following command in a terminal:
Since I already had the Android SDK installed from when building another project I figured I could run it directly. But i got this error:
The solution according to stack overflow was to do this:
After installing Android Studio I got a few questions to update and install SDK-components I didn’t have. I accepted them all.
After that i opened the platforms/android project in android studio and tried to run it in a Simulator. And in this step Android Studio wanted to install a simulator. So it did install the Android_Accelerated_X86. If you choose the other one it will be slow and not be able to start the ionic app. At least I got the error message that it couldnt find the folder android_asset.
Android Studio run app
But the simulator couldn’t open the app. At this point I figured I should delete the ionic android project and add it again. So close Android studio.
Delete an Ionic platform
To remove a platform run this command in a terminal:
The next step was to make sure i’ve got the latest Ionic and Cordova version.
Open the file resources/splash.png and edit it as you wish. The dimensions are 2208x2208 pixels. The icon is called.. you guessed it.. icon.png and is located in the same folder. The dimensions for the icon is 1024x1024 pixels.
I’m aiming to release Dogwalk quickly, and then update the app functions and look after the app is already published. So I put little effort into the design of the icon and splash screen. They turned out like this:
Ionic 2 dogwalk icon
Ionic 2 dogwalk splash screen
Now when the following command is executed Ionic will take care of generating the correct dimensions for the splash screen and icon.
If you run that command without having created a splash screen and icon yourself Ionic will use the default ones.
This tutorial covers how to add markers on a Google map in an Ionic 2 app. We’ll continue where we left of the last with a Google map that is displayed in our app. If you haven’t already got that take a look at that tutorial first.
1. Markers JSON
To keep it simple we’ll store the marker information in a json file. Add a file called markers.json in the folder src/assets/data/ (create the folder data since it is not created by default).
The data we need at this point for a marker is, latitude, longitude and name. If you need help to find the latitude and longitude for your markers you can use maapcoordinates.net. My markers.json looks like this:
2. Loading JSON in Ionic 2 and Angular 2
To load our .JSON file we’ll be using angular http and something called an Observable which we’ll map with rxjs/add/operator/map. You can read more about these classes in the Http class documentation of Angular 2
Start by importing these into src/pages/home/home.ts
Then we also need to add Http to our constructor:
Now create a method called getMarkers in home.ts. In that method we’ll load the json file:
We are subscribing to an observable to get the markers. And in the subscribe method we will use the marker data to display them on the map.
3. Displaying markers on a Google map
Create a method called addMarkersToMap() in home.ts. In that method the markers will be looped through and added to the map.
Now we need to call this method from the subscribe callback of getMarkers():
That is all that is needed to display a marker on a Google map in Ionic 2 with Angular 2.
In this post we will look at implementing Google maps in an Ionic 2 app. The app I’m building is called Dogwalk. It’s going to display markers on a map where it’s a nice area to walk your dog.
This is a continuation of the Installing Ionic post, so start there if you haven’t already got an app to add the map to.
Adding Google maps API
Open up the src/index.html file and add a script reference to the Google maps API. Read the google docs to get an API key
Then open up src/pages/home/home.html and add a div which will contain the map so that the full .html file looks like this:
Editing the home component to show maps
edit src/page/home/home.ts to look like this:
I got this from Josh Morony. But I changed the ionViewLoaded event to ionViewWillEnter (which i couldn’t get to work, and isn’t documented). I also added a custom style to the map.
If you do not want the style just remove styles from the map options array. Or if you would like another look on your map take a look at Snazzy maps.
Then edit the src/pages/home/home.scss to look like this:
That will get the google map to work.
Ionic2 Google maps - iOS Simulator displaying dogwalk app