1552013332
Geocoding is the process of taking latitude and longitude to determine an address, or taking an address and producing latitude and longitude coordinates.
There are numerous reasons an application needs to use a geocoder. For Now Serving, we use it during the sign up process, as well as making it easy to find nearby restaurants with a single click of ‘Find Me’.
Let’s get to coding!
We’ll need to grab the mapbox-sdk
and add it to the Gemfile.
_gem_ **'mapbox-sdk'**, **'~>2'**
Create a simple initializer to set the access token in your app (e.g config/initializers/mapbox.rb
)
**_Mapbox_**.access_token = MAPBOX_ACCESS_TOKEN
Next, let’s add a couple routes:
_namespace_ **:address_search do** _get_ **'expand'**, **to**: **'expand'** _get_ **'parse'**, **to**: **'parse' end**
And an address_search_controller.rb
:
class AddressSearchController < ApplicationControllerTake an addresss and return lat/lng
def expand
begin
@addresses = Mapbox::Geocoder.geocode_forward(address_params[:a]) unless address_params[:a].nil?
render template: ‘address_search/result’
rescue StandardError
render json: { errors: [‘Unable to perform forward geocoding’] }
end
endTake lat/lng array and return a postal address
def parse
begin
@location = { latitude: address_params[:latitude].to_f, longitude: address_params[:longitude].to_f }
@addresses = Mapbox::Geocoder.geocode_reverse(@location)
render template: ‘address_search/result’
rescue StandardError
render json: { errors: [‘Unable to perform reverse geocoding’] }
end
endprivate
def address_params
params.permit(:a, :latitude, :longitude)
end
end
The expand method takes the a
query params and asks the geocoder service to return a latitude/longitude array. For getting an address from lat/lng we are expecting a hash like { latitude: 0, longitude: 0 }
.
You may not want to render a template here but in my case I wanted to always return an array, so the best way to ensure that happened was rendering it with jbuilder one-liner:
json.array! @addresses
And a request spec:
RSpec.describe ‘Address Search’ doit ‘parses an address and returns latitude and longitude’ do
get ‘/api/v1/address_search/expand’, params: { a: ‘401 B St, San Diego CA’ }
expect(response).to be_successful
endit ‘parses latitude and longitude and returns an address’ do
get ‘/api/v1/address_search/parse’, params: { longitude: 127.0, latitude: -43.64}
expect(response).to be_successful
end
end
We’re using the awesome NuxtJS framework for our UI. If you haven’t used it before, definitely give it a look. If you can’t use it, don’t worry; this code will work fine without Nuxt.
We use Vuex actions to call our back end, so we have a store for our Mapbox configuration.
export const actions = {
locate({ commit }, { longitude, latitude }) {
return this.$axios.get(‘/address_search/parse’, { params: { longitude: longitude, latitude: latitude } })
},
coordinate({ commit }, params) {
return this.$axios.get(‘/address_search/expand’, { params: { a: params } })
}
}
For presentation, we use vue-i18n, vue-notify, bootstrap-vue
and vue-fontawesome
.
<template>
<b-btn
v-b-tooltip.hover=“true”
:data-state=“state”
:variant=“btnVariant”
:title=“locationLabel”
type=“button”
@click=“findMe”>
<font-awesome-icon v-if=“state === 1” :icon=“[‘far’, ‘spinner’]” spin />
<font-awesome-icon v-else :icon=“[‘far’, ‘location-arrow’]” />
</b-btn>
</template>
<script>
import { FontAwesomeIcon } from ‘@fortawesome/vue-fontawesome’export default {
components: {
FontAwesomeIcon
},
props: {
locationLabel: {
default: ‘Find my current location’,
type: String
}
},
data() {
return {
state: 0
}
},
computed: {
btnVariant() {
switch (this.state) {
case 0:
return ‘outline-primary’
case 1:
return ‘info’
case 2:
return ‘success’
default:
return ‘outline-primary’
}
}
},
methods: {
findMe() {
const vm = this
this.state = 1
if (!navigator.geolocation) {
vm.$notify({ text: vm.$t(‘geolocation.not_supported’), group: ‘alerts’ })
return
}function success(position) { const accuracy = position.coords.accuracy vm.$store.dispatch('mapbox/locate', { latitude: position.coords.latitude, longitude: position.coords.longitude, accuracy: accuracy }) .then((resp) => { vm.state = 2 vm.$emit('result', { name: resp.data[0].features[0].place_name, center: resp.data[0].features[0].center }) }) .catch(() => { vm.state = 0 vm.$notify({ text: vm.$t('geolocation.not_found'), type: 'warning', group: 'alerts' }) }) } function error() { vm.$notify({ text: vm.$t('geolocation.not_found'), group: 'alerts', type: 'warning' }) } navigator.geolocation.getCurrentPosition(success, error) }
}
}
</script>
There’s a lot going on here, so lets break it all down.
The location button has three states; default state, active state, and a success state. The computed property handles changing out the css classes for each state.
There is also a tooltip that displays on hover to explain that the browser will ask for permission to send location information to the back end.
The findMe
method is called on click. In it we have two callbacks for success and error that the browser’s built in [getCurrentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition)
needs to work correctly. When the browser provides the latitude and longitude to the success
callback, we can send that to the back end using the Vuex action. Once the back end response comes, the component emits a result event containing the address name and coordinates. If permission is denied, we display an error notification. Also if the browser doesn’t support location services, we notify the user of that case.
Congrats you have a fully implemented API for forward and reverse geocoding solution!
Originally published by Todd Baur at https://itnext.io
☞ The Complete Ruby on Rails Developer Course
☞ Testing Ruby with RSpec: The Complete Guide
☞ How to build Instagram using Ruby on Rails
☞ Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
☞ Nuxt JS with Laravel - Build API driven SSR Vue JS Apps
#vue-js #nuxt-js #ruby-on-rails
1594024630
Want to Hire VueJS Developer to develop an amazing app?
Hire Dedicated VueJS Developers on the contract (time/project) basis providing regular reporting about your app. We, at HourlyDeveloper.io, implement the right strategic approach to offer a wide spectrum of vue.js development services to suit your requirements at most competitive prices.
Consult with us:- https://bit.ly/2C5M6cz
#hire dedicated vuejs developers #vuejs developer #vuejs development company #vuejs development services #vuejs development #vuejs developer
1620729846
Can you use WordPress for anything other than blogging? To your surprise, yes. WordPress is more than just a blogging tool, and it has helped thousands of websites and web applications to thrive. The use of WordPress powers around 40% of online projects, and today in our blog, we would visit some amazing uses of WordPress other than blogging.
What Is The Use Of WordPress?
WordPress is the most popular website platform in the world. It is the first choice of businesses that want to set a feature-rich and dynamic Content Management System. So, if you ask what WordPress is used for, the answer is – everything. It is a super-flexible, feature-rich and secure platform that offers everything to build unique websites and applications. Let’s start knowing them:
1. Multiple Websites Under A Single Installation
WordPress Multisite allows you to develop multiple sites from a single WordPress installation. You can download WordPress and start building websites you want to launch under a single server. Literally speaking, you can handle hundreds of sites from one single dashboard, which now needs applause.
It is a highly efficient platform that allows you to easily run several websites under the same login credentials. One of the best things about WordPress is the themes it has to offer. You can simply download them and plugin for various sites and save space on sites without losing their speed.
2. WordPress Social Network
WordPress can be used for high-end projects such as Social Media Network. If you don’t have the money and patience to hire a coder and invest months in building a feature-rich social media site, go for WordPress. It is one of the most amazing uses of WordPress. Its stunning CMS is unbeatable. And you can build sites as good as Facebook or Reddit etc. It can just make the process a lot easier.
To set up a social media network, you would have to download a WordPress Plugin called BuddyPress. It would allow you to connect a community page with ease and would provide all the necessary features of a community or social media. It has direct messaging, activity stream, user groups, extended profiles, and so much more. You just have to download and configure it.
If BuddyPress doesn’t meet all your needs, don’t give up on your dreams. You can try out WP Symposium or PeepSo. There are also several themes you can use to build a social network.
3. Create A Forum For Your Brand’s Community
Communities are very important for your business. They help you stay in constant connection with your users and consumers. And allow you to turn them into a loyal customer base. Meanwhile, there are many good technologies that can be used for building a community page – the good old WordPress is still the best.
It is the best community development technology. If you want to build your online community, you need to consider all the amazing features you get with WordPress. Plugins such as BB Press is an open-source, template-driven PHP/ MySQL forum software. It is very simple and doesn’t hamper the experience of the website.
Other tools such as wpFoRo and Asgaros Forum are equally good for creating a community blog. They are lightweight tools that are easy to manage and integrate with your WordPress site easily. However, there is only one tiny problem; you need to have some technical knowledge to build a WordPress Community blog page.
4. Shortcodes
Since we gave you a problem in the previous section, we would also give you a perfect solution for it. You might not know to code, but you have shortcodes. Shortcodes help you execute functions without having to code. It is an easy way to build an amazing website, add new features, customize plugins easily. They are short lines of code, and rather than memorizing multiple lines; you can have zero technical knowledge and start building a feature-rich website or application.
There are also plugins like Shortcoder, Shortcodes Ultimate, and the Basics available on WordPress that can be used, and you would not even have to remember the shortcodes.
5. Build Online Stores
If you still think about why to use WordPress, use it to build an online store. You can start selling your goods online and start selling. It is an affordable technology that helps you build a feature-rich eCommerce store with WordPress.
WooCommerce is an extension of WordPress and is one of the most used eCommerce solutions. WooCommerce holds a 28% share of the global market and is one of the best ways to set up an online store. It allows you to build user-friendly and professional online stores and has thousands of free and paid extensions. Moreover as an open-source platform, and you don’t have to pay for the license.
Apart from WooCommerce, there are Easy Digital Downloads, iThemes Exchange, Shopify eCommerce plugin, and so much more available.
6. Security Features
WordPress takes security very seriously. It offers tons of external solutions that help you in safeguarding your WordPress site. While there is no way to ensure 100% security, it provides regular updates with security patches and provides several plugins to help with backups, two-factor authorization, and more.
By choosing hosting providers like WP Engine, you can improve the security of the website. It helps in threat detection, manage patching and updates, and internal security audits for the customers, and so much more.
#use of wordpress #use wordpress for business website #use wordpress for website #what is use of wordpress #why use wordpress #why use wordpress to build a website
1552013332
Geocoding is the process of taking latitude and longitude to determine an address, or taking an address and producing latitude and longitude coordinates.
There are numerous reasons an application needs to use a geocoder. For Now Serving, we use it during the sign up process, as well as making it easy to find nearby restaurants with a single click of ‘Find Me’.
Let’s get to coding!
We’ll need to grab the mapbox-sdk
and add it to the Gemfile.
_gem_ **'mapbox-sdk'**, **'~>2'**
Create a simple initializer to set the access token in your app (e.g config/initializers/mapbox.rb
)
**_Mapbox_**.access_token = MAPBOX_ACCESS_TOKEN
Next, let’s add a couple routes:
_namespace_ **:address_search do** _get_ **'expand'**, **to**: **'expand'** _get_ **'parse'**, **to**: **'parse' end**
And an address_search_controller.rb
:
class AddressSearchController < ApplicationControllerTake an addresss and return lat/lng
def expand
begin
@addresses = Mapbox::Geocoder.geocode_forward(address_params[:a]) unless address_params[:a].nil?
render template: ‘address_search/result’
rescue StandardError
render json: { errors: [‘Unable to perform forward geocoding’] }
end
endTake lat/lng array and return a postal address
def parse
begin
@location = { latitude: address_params[:latitude].to_f, longitude: address_params[:longitude].to_f }
@addresses = Mapbox::Geocoder.geocode_reverse(@location)
render template: ‘address_search/result’
rescue StandardError
render json: { errors: [‘Unable to perform reverse geocoding’] }
end
endprivate
def address_params
params.permit(:a, :latitude, :longitude)
end
end
The expand method takes the a
query params and asks the geocoder service to return a latitude/longitude array. For getting an address from lat/lng we are expecting a hash like { latitude: 0, longitude: 0 }
.
You may not want to render a template here but in my case I wanted to always return an array, so the best way to ensure that happened was rendering it with jbuilder one-liner:
json.array! @addresses
And a request spec:
RSpec.describe ‘Address Search’ doit ‘parses an address and returns latitude and longitude’ do
get ‘/api/v1/address_search/expand’, params: { a: ‘401 B St, San Diego CA’ }
expect(response).to be_successful
endit ‘parses latitude and longitude and returns an address’ do
get ‘/api/v1/address_search/parse’, params: { longitude: 127.0, latitude: -43.64}
expect(response).to be_successful
end
end
We’re using the awesome NuxtJS framework for our UI. If you haven’t used it before, definitely give it a look. If you can’t use it, don’t worry; this code will work fine without Nuxt.
We use Vuex actions to call our back end, so we have a store for our Mapbox configuration.
export const actions = {
locate({ commit }, { longitude, latitude }) {
return this.$axios.get(‘/address_search/parse’, { params: { longitude: longitude, latitude: latitude } })
},
coordinate({ commit }, params) {
return this.$axios.get(‘/address_search/expand’, { params: { a: params } })
}
}
For presentation, we use vue-i18n, vue-notify, bootstrap-vue
and vue-fontawesome
.
<template>
<b-btn
v-b-tooltip.hover=“true”
:data-state=“state”
:variant=“btnVariant”
:title=“locationLabel”
type=“button”
@click=“findMe”>
<font-awesome-icon v-if=“state === 1” :icon=“[‘far’, ‘spinner’]” spin />
<font-awesome-icon v-else :icon=“[‘far’, ‘location-arrow’]” />
</b-btn>
</template>
<script>
import { FontAwesomeIcon } from ‘@fortawesome/vue-fontawesome’export default {
components: {
FontAwesomeIcon
},
props: {
locationLabel: {
default: ‘Find my current location’,
type: String
}
},
data() {
return {
state: 0
}
},
computed: {
btnVariant() {
switch (this.state) {
case 0:
return ‘outline-primary’
case 1:
return ‘info’
case 2:
return ‘success’
default:
return ‘outline-primary’
}
}
},
methods: {
findMe() {
const vm = this
this.state = 1
if (!navigator.geolocation) {
vm.$notify({ text: vm.$t(‘geolocation.not_supported’), group: ‘alerts’ })
return
}function success(position) { const accuracy = position.coords.accuracy vm.$store.dispatch('mapbox/locate', { latitude: position.coords.latitude, longitude: position.coords.longitude, accuracy: accuracy }) .then((resp) => { vm.state = 2 vm.$emit('result', { name: resp.data[0].features[0].place_name, center: resp.data[0].features[0].center }) }) .catch(() => { vm.state = 0 vm.$notify({ text: vm.$t('geolocation.not_found'), type: 'warning', group: 'alerts' }) }) } function error() { vm.$notify({ text: vm.$t('geolocation.not_found'), group: 'alerts', type: 'warning' }) } navigator.geolocation.getCurrentPosition(success, error) }
}
}
</script>
There’s a lot going on here, so lets break it all down.
The location button has three states; default state, active state, and a success state. The computed property handles changing out the css classes for each state.
There is also a tooltip that displays on hover to explain that the browser will ask for permission to send location information to the back end.
The findMe
method is called on click. In it we have two callbacks for success and error that the browser’s built in [getCurrentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition)
needs to work correctly. When the browser provides the latitude and longitude to the success
callback, we can send that to the back end using the Vuex action. Once the back end response comes, the component emits a result event containing the address name and coordinates. If permission is denied, we display an error notification. Also if the browser doesn’t support location services, we notify the user of that case.
Congrats you have a fully implemented API for forward and reverse geocoding solution!
Originally published by Todd Baur at https://itnext.io
☞ The Complete Ruby on Rails Developer Course
☞ Testing Ruby with RSpec: The Complete Guide
☞ How to build Instagram using Ruby on Rails
☞ Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
☞ Nuxt JS with Laravel - Build API driven SSR Vue JS Apps
#vue-js #nuxt-js #ruby-on-rails
1622462142
Ruby on Rails is a development tool that offers Web & Mobile App Developers a structure for all the codes they write resulting in time-saving with all the common repetitive tasks during the development stage.
Want to build a Website or Mobile App with Ruby on Rails Framework
Connect with WebClues Infotech, the top Web & Mobile App development company that has served more than 600 clients worldwide. After serving them with our services WebClues Infotech is ready to serve you in fulfilling your Web & Mobile App Development Requirements.
Want to know more about development on the Ruby on Rails framework?
Visit: https://www.webcluesinfotech.com/ruby-on-rails-development/
Share your requirements https://www.webcluesinfotech.com/contact-us/
View Portfolio https://www.webcluesinfotech.com/portfolio/
#ruby on rails development services #ruby on rails development #ruby on rails web development company #ruby on rails development company #hire ruby on rails developer #hire ruby on rails developers
1598839653
Due to the inability to generate a well-defined way to authenticate rails API, I have sourced out this information in order to help me and you have a way of authenticating our rails API token. This tutorial would be based on the latest version (6.0) of Ruby on Rails.
In getting this set up as well as up and doing, the few steps through which the processes would be implemented are listed below:
Step 1:
We would need to, first of all, generate a new rails app as we embark on the journey. Follow the example given below:
$ rails new sample-app --api -d=postgresql -T
$ cd sample-app
$ rails db:create
$ rails db:migrate
Step 2:
In order to gain access to the API, we would need to uncomment or remove Cors gems as that serves as permission into gaining access to the API
gem “rack-cors”
After uncommented the gem ‘rack-cors’ then we run this command below
$ bundle install
#ruby-on-rails #rails #rails-api #knock-gem #ruby #software-development #rails-only-api