Travel AR app with Huawei AR Engine and Huawei Map Kit
Hello, in our article today, we will develop an application using Huawei Map Kit and Huawei AR Engine and we will see the monuments in the world with AR Engine.
After first creating our Android project, you can take a look at the following article for HMS Core integration processes:
Android | Integrating Your Apps With Huawei HMS Core
In this article, I will explain how you can integrate Huawei Mobile Services. Integrating Huawei Mobile Services (HMS)…
We start our application by adding the following dependencies.
We add internet permissions for Huawei Map kit and camera permissions for AR Engine to our AndroidManifest file.
In the application ,TravelAR, we can show our markers on the map with the custom markers provided by the Huawei Map Kit.
We can customize our marker using the MarkerOptions class. You can determine the location of the marker with the position() function, and we must specify the file we added for the marker icon.
After creating our own special markers with the Huawei Map Kit, we must listen to the setOnMarkerClickListener function to assign the click property of these markers and send them to the other activity.
We listen for the click event for the marker with the setOnMarkerClickListener function from the HuaweiMap class. With Intent, we sent the markerTitle value to the other activity because we will list our models according to the clicked object.
With Huawei AR Engine, we can view our virtualized reality models in the real world. Currently, AR Engine supports many functionalities such as motion tracking, environment tracking, and human body and face tracking.
Now let’s look at our activity class, where we show our models with the AR Engine part, which is the other part of our project.
We need to add our model files with .obj extension to our project by creating an assets folder.
You can find the integration process with Huawei AR Engine from the article below:
We get our markerTitle variable, which we sent with Intent from the previous activity class, with getIntent in our WorldActivity class.
Our RenderManager class is the class we use to create virtual objects and manage these objects. We need to implement the GlSurfaceRenderer interface. This interface has 3 methods we need to implement.
In our Manager class, we will send our variable named markerTitle to our ObjectDisplay class that we will use for our objects in our onSurfaceCreated function. The ObjectDisplay class is the class we use to draw virtual objects.
Our onSurfaceCreated method is the function we use when our surface is first created or recalled.
In our readObject function in our ObjectDisplay class, we open the model file we want to see on the screen with InputStream and perform the reading process. Then we will send the return value of this function to our initializeGlObjectData function.
As we can see above, we read our files with .obj extension according to our markerTitle variable and sent them to our initializeGlObjectData function.
Another important function in our ObjectDisplay class that we should mention is the onDrawFrame function. With the onDrawFrame function, we use it to draw a virtual object at a specific position on a certain plane. This function is called in onDrawFrame in our RenderManager class. In this method, we can adjust the light and color aspects of the object.
In this article, we examined how to create custom markers on the map and view our virtual objects on the real world using Huawei Map Kit and Huawei AR Engine.
For more information:
You can ask your questions and find solutions on the Huawei Developer forum: