Mobile App Development

Google Map on Android Wear OS

One of the easiest and most powerful uses of your smartwatch is getting directions, and the experience is particularly good on Google’s Wear OS products.

There’s just no better solution for those days when you don’t want to keep searching at your screen for turn-by-turn directions because it’s powered by Google Maps.

There are a few things to keep in mind when getting this app: it won’t come pre-installed on your Wear smartwatch, and it won’t function the same for iPhone users as it does for Android users.

You can build a map-based wearable app that runs directly on Wear OS through Google devices using the Maps SDK for Android. Your app’s users can see their positions on the globe by just looking at their wrists. They can, for example, map their location on a street, then zoom in for more information, or tap a marker to see a data window provided by your app.

Get underway with Wear OS today.

Using the Maps SDK for Android to create a wearable app is fundamentally the same as creating a Google Maps app for any other Android smartphone. The distinction is in your architecture for the wearable device’s smaller form factor, which optimises the app’s usability and efficiency.

Since it simplifies project setup, library inclusion, and packing, Android Studio is the preferred tool for Wear OS creation.

[Also Read: Android 12 – Things You Need To Know About It]

Create the first Wear OS map app.

This short guide assumes you’re familiar with the Android Maps SDK, that you’ve followed the Wear OS instructions to build a wearable module in your smartphone, and that you now want to add a map to it.



Initial Gradle setup

// Support ambient mode.
compileOnly ‘com.google.android.wearable:wearable:2.5.0’

// Google Play Services.
implementation ‘com.google.android.gms:play-services-maps:17.0.0’

First Manifest File

<!– This make app indetify as a Wear OS app. –>
<uses-feature android:name=”android.hardware.type.watch” />

<!– Permission required for ambient mode to keep the application running. –>
<uses-permission android:name=”android.permission.WAKE_LOCK” />

in (<application..> ….. </application>) we have to put our Google map API as a metadata

<!– API key for the Android Maps API v2. The value is defined as a string resource. –>
<meta-data android:name=”com.google.android.geo.API_KEY”
android:value=”@string/google_maps_key”/>

<uses-library android:name=”com.google.android.wearable” android:required=”false” />

Now UI Part in XML file activity_main.xml

<FrameLayout
xmlns:android=”http://schemas.android.com/apk/res/android
xmlns:map=”http://schemas.android.com/apk/res-auto
android:id=”@+id/root_container”
android:layout_height=”match_parent”
android:layout_width=”match_parent”>

<FrameLayout
android:id=”@+id/map_container”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>

<fragment
android:id=”@+id/map”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:name=”com.google.android.gms.maps.MapFragment”/>

</FrameLayout>

</FrameLayout>

Backend JAVA code have implement Google library

public class MainActivity extends WearableActivity implements OnMapReadyCallback {

// Pre Define Lat Lng
private static final LatLng BytesTechno = new LatLng(23.0302559, 72.5299926);

private GoogleMap mMap;
private MapFragment mMapFragment;

public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.activity_main);

// Enable ambient support, so the map remains visible in simplified, low-color display
// when the user is no longer actively using the app but the app is still visible on the
// watch face.
setAmbientEnabled();

final FrameLayout topFrameLayout = (FrameLayout) findViewById(R.id.root_container);
final FrameLayout mapFrameLayout = (FrameLayout) findViewById(R.id.map_container);

// Set the system view insets on the containers when they become available.
topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
// Call through to super implementation and apply insets
insets = topFrameLayout.onApplyWindowInsets(insets);

FrameLayout.LayoutParams params =
(FrameLayout.LayoutParams) mapFrameLayout.getLayoutParams();

// Add Wearable insets to FrameLayout container holding map as margins
params.setMargins(
insets.getSystemWindowInsetLeft(),
insets.getSystemWindowInsetTop(),
insets.getSystemWindowInsetRight(),
insets.getSystemWindowInsetBottom());
mapFrameLayout.setLayoutParams(params);

return insets;
}
});

// Obtain the MapFragment and set the async listener to be notified when the map is ready.
mMapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mMapFragment.getMapAsync(this);
}

/**
* Starts ambient mode on the map.
*/
@Override
public void onEnterAmbient(Bundle ambientDetails) {
super.onEnterAmbient(ambientDetails);
mMapFragment.onEnterAmbient(ambientDetails);
}

@Override
public void onMapReady(GoogleMap googleMap) {
// Map is ready to be used.
mMap = googleMap;

// Set the long click if any event need to set mMap.setOnMapLongClickListener(this);

// Add a marker with a title.
mMap.addMarker(new MarkerOptions().position(BytesTechno)
.title(“Bytes Technolab”));

// Move the camera to show the marker.
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(BytesTechno, 10));
}

}

The Google API key will be registered by https://console.cloud.google.com/
After select or registered the project go to API Library and enable Maps SDK for Android
Once done Create credentials to access your enabled APIs, you have to generate a new API and copy generated key, and put it into our project.

And the result is:


Common problems

It’s important to remember that the experience can be inconsistent, even when attached to an Android phone.

The map hasn’t always appeared, and the turn-by-turn instructions haven’t always appeared before the whole app has been opened on the tablet.

It’s unclear if this is an intentional move by Google after Maps first launched on Wear, but it seems to differ from watch to watch with no discernible pattern.

Wrapping up

So this is how you can easily get Google Map on Android Wear OS. Android development is advancing in a menacing speed these days with many new innovations taking over the market. One can easily Hire Android developers or get help from Android app development company to get started with Google Map on Android Wear OS

Related Blogs

Selecting the Best Adobe Experience Manager Solution for Your Needs

Selecting the Best Adobe Experience Manager Solution for Your Needs

Creating and managing engaging content across various platforms is important for eCommerce stores in this ever-evolving digital commerce era. Th...

How Adobe Commerce Development Partner Boosts Your eCommerce Success?

How Adobe Commerce Development Partner Boosts Your eCommerce Success?

Modern retail owners have turned to accredited eCommerce development companies as their technical consulting and implementation partners. By han...

What Are the Top Security Threats to Adobe Commerce Stores?

What Are the Top Security Threats to Adobe Commerce Stores?

Most businesses are looking to expand their presence in the online marketplace and that’s led to the growth of eCommerce platforms like Adobe ...