Android SpeedoMeter Tutorial using Google Location Service

Hi there, in this Android SpeedoMeter Tutorial you will learn how to fetch your live speed, distance and duration on your android app as you move around with your phone. This Android SpeedoMeter app makes use …

android speedometer tutorial

Hi there, in this Android SpeedoMeter Tutorial you will learn how to fetch your live speed, distance and duration on your android app as you move around with your phone. This Android SpeedoMeter app makes use of the Google’s Location Service to calculate the speed of your mobile. It’s quite simple the way it functions. You can see the sample output of this Android Speedometer in the below image.

android speedometer tutorial
Android Speedometer

That’s what you are gonna get through in this project. So, Let’s get started with it.

Creating our Android SpeedoMeter

New Android Studio Project

So now lets begin creating our Android Speedometer.

  • As usual, begin with creating a new Android Studio Project with empty Activity.
  • To access the Google’s Location Service, add google play services dependency to your app level gradle and then sync it.

Creating a Location Service

  • Create a class named LocationService.java and add the following code. It consists of a method called updateUI() which updates the live values of the Speed, Distance and Duration.

  • Now, when we have created the Location Service, its time to configure the uses of this service and that’ll be done in MainActivity.java. Hence, add the following code to your MainActivity.java. It consists of  methods to bind and unbind  the location service  as per required.

  • By now, we are done with the Java part.

Creating User Interface

  • Now, we need to configure the activity_main.xml. Add the following code to activity_main.xml which consists of TextViews to display the speed, distance and duration and some buttons.

  • We are almost done. Just update the AndroidManifest.xml and mention the Location Service as it is in the code below.
  • Please note that the app will only work below Android Lollipop versions. If you want to make the app work in above Android Lollipop then you need to ask the permissions at run time. To modify this app and ask the permission at run time you can refer to this Android Marshmallow Permission Example Tutorial.

  • And you did it.  Run the app now and hit the start calculating button. It would ask you to enable your gps. As you do, its gonna fetch your location and then show your live speed and all.
  • If you are facing some problems then you can download my source code from the link given below.

[sociallocker id=1372] Android SpeedoMeter Example Source Code [/sociallocker]

If you still find some problem, let me know in the comments section I will try my best to sort out your queries. Thank You 🙂

Hello, I am Manish Kumar. I am a B.Tech Student at NIT Jamshedpur. Fortunately, I find myself quite passionate about Computers and Technology. Android is my most recent Crush.

Expand Your Knowledge: Next Tutorial Picks

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x