Skip to content

pbaris/jmix-google-place

Repository files navigation

license

Google Place add-on for Jmix

This add-on provides:

  • A custom data type for representing a Google Place.

  • A related field that allows users to select a Google Place.

  • Two predefined fragments:

    • A fragment for displaying the rating and user reviews of a Google Place.

    • A fragment for presenting detailed information about a Google Place.

preview

Installation

The following table shows which version of the add-on is compatible with which version of the platform:

Jmix Version Add-on Version Implementation

2.4.4

1.0.0

gr.netmechanics.jmix:jmix-google-place-starter:1.0.0

2.5.x

1.1.0

gr.netmechanics.jmix:jmix-google-place-starter:1.1.0

2.6.x

1.2.0

gr.netmechanics.jmix:jmix-google-place-starter:1.2.0

2.7.x

1.3.0

gr.netmechanics.jmix:jmix-google-place-starter:1.3.0

2.8.x

1.4.0

gr.netmechanics.jmix:jmix-google-place-starter:1.4.0

For manual installation, add the following dependencies to your build.gradle:

implementation 'gr.netmechanics.jmix:jmix-google-place-starter:<addon-version>'

Configuration

There are two settings to specify.

Setting Type Default Value Description

jmix.gplace.apiKey

Required

Google API key.

jmix.gplace.languageCode

Optional

en

The language in which to return results and for map UI elements and tile labels.

By default, you can define those settings in application.properties file.

Alternatively, implement a Spring bean of type gr.netmechanics.jmix.gplace.GPlacePropertiesProvider to provide these settings (e.g. to use Jmix Application Settings add-on).

Note

The add-on uses Google’s Places API (New) and the Maps Embed API (optional).

The Google API key must support the Places API (New). Additionally, if you intend to use the Google Place Info Fragment, the key must also support the Maps Embed API.

How to use the add-on

Datatype

Add-on provides a new datatype GooglePlaceRef.

You can define an entity attribute with the GooglePlaceRef datatype using Studio.

studio1

As a result, Studio generates the following attribute definition:

@Column(name = "PLACE")
private GooglePlaceRef place;
Note

The actual value stored in the database is a JSON string.

{"id":"ChIJ__tbmhQR0q7gENr8mSs","displayName":"Heraklion International Airport N. Kazantzakis","address":"Heraklion 716 01, Greece","latitude":35.3395461,"longitude":25.1760645}

Field

In a detail view you can add the field from studio Component Palette window

studio2

or through code

<view xmlns="http://jmix.io/schema/flowui/view"
        xmlns:nm="http://schemas.netmechanics.gr/jmix/ui"
        focusComponent="form">
    ...
    <layout>
        <formLayout id="form">
            <nm:googlePlacePicker id="placeField" property="place"/>
        </formLayout>
        ...
    </layout>
</view>

Fragments

Google Place Rating Fragment

A fragment for displaying the rating and user reviews of a Google Place.

fragment rating
Usage
<fragment class="gr.netmechanics.jmix.gplace.component.GooglePlaceRatingFragment">
    <properties>
        <property name="placeId" value="ChIJbVXA_SNamhQRGtyjFLUFH9E"/>
    </properties>
</fragment>
Properties
Property Type Default Value Description

placeId

Required

The place ID for which to display rating and user reviews.

apiKey

Optional

<config>

Google API key. If not specified, the key from the configuration will be used.

languageCode

Optional

<config>

Specifies the language for UI elements and map tile labels. If not specified, the key from the configuration will be used.

useGoogleIcon

Optional

true

Specifies whether to use the Google icon. If not, the place icon provided by the Google Places Service will be used.

hideReviews

Optional

false

Specifies whether the reviews will be hidden.

Google Place Info Fragment

A fragment for presenting detailed information about a Google Place.

fragment info
Usage
<fragment class="gr.netmechanics.jmix.gplace.component.GooglePlaceInfoFragment">
    <properties>
        <property name="placeId" value="ChIJbVXA_SNamhQRGtyjFLUFH9E"/>
    </properties>
</fragment>
Properties
Property Type Default Value Description

placeId

Required

The place ID for which to display detailed information.

apiKey

Optional

<config>

Google API key. If not specified, the key from the configuration will be used.

languageCode

Optional

<config>

Specifies the language for map UI elements and tile labels. If not specified, the key from the configuration will be used.

useGoogleIcon

Optional

true

Specifies whether to use the Google icon. If not, the place icon provided by the Google Places Service will be used.

hideMap

Optional

false

Specifies whether the map will be hidden.

hideOpeningHours

Optional

false

Specifies whether the opening hours information will be hidden.

zoom

Optional

14

Initial zoom level of the map.

mapType

Optional

roadmap

Specifies the type of map tiles to load.
roadmap or satellite

Cache Cleaning Scheduler

The add-on caches requests to Google’s APIs. It includes a built-in cleaning Quartz job, which is disabled by default. You can use it for periodic cache cleaning, as described below.

Quartz Configuration

To use the configuration of the Quartz job for cache cleaning, do the following:

  1. Include Quartz add-on in your project as described in the Quartz / Installation.

  2. Set the jmix.gplace.use-default-cleaning-cache-quartz-configuration property to true:

    jmix.gplace.use-default-cleaning-cache-quartz-configuration=true
  3. Change the CRON expression if necessary using the jmix.gplace.cleaning-cache-cron property.

    jmix.gplace.cleaning-cache-cron=0 0 1 1 1/1 ? *

About

This add-on provides a custom data type for representing Google Places, along with UI components for selecting and displaying detailed information and user reviews of these places.

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

 
 
 

Contributors