Fetch Google Map Service: Part 2- App Dev Series 5

Objective: get the location data by using LocationService.

In this article, we will continue receiving location data from user’s device and display it on app. At the end of building this function, you might need to install the app on your own device to check the result.

Get the coordinate

After we enabled Google Map Service and request the data from url in the previous article, we will get the location data by using LocationService.
First we need to make Start() as an IEnumerator, and inside this coroutine, we have to finish the process step by step.

At the beginning, we need to check if user has authenticate the permission of using location data.

If user has authenticated the permission, we can move on to start the location service.
Start the service with one line: Input.location.Start().

Then we need to set a timer as a maximum waiting time of initiate this service. We will use a While() loop to do this part, and make it return error message if waiting for over 20 seconds.

If location service is failed to initialize, send the error message.
Otherwise, the location service has successfully receive the location data, and store it to the variables of coordinate.

When we received the data, stop this service.

At the end of this method, we can send error message when user has not enable location service at the beginning. Use it as else statement under checking the if statement of enable location service.

All done! This would be the whole Start() looks like when finish this part.

Unfortunately, we could not use this location service in Play mode, you need to build this app to test it.
Once you successfully installed this app, make sure enable the location service in the Settings, and start the app.

If you can see the current location on your app, you did a wonderful job!

--

--

--

A passionate gamer whose goal is to work in video game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Facelock + AWS +Email + Whatsapp

Integrate AEM 6.5 with LDAP using JumpCloud ldap-as-a-service

OWASP Top 10 — INJECTION!!

Autonomous & aligned teams at Unity

How, I got the best Woo-Commerce mobile App and saved my time.

Clojure vs Elixir —Bootstrapping

A Beginner’s Guide to iOS App Development

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Building A Stealth Game — Helping Your Guards “See”

In ABAP Make an API HTTP Request. / ABAP HTTP Request

Optimizing Unity Workflow Using Layouts

Daily Progression: Generate a Case Number!