Java Client for TimeZone api from Google Maps

Java Client for TimeZone api from Google Maps

IDE Used : Eclipse

I have developed this Test class on Play framework 2.3.10 so using build.sbt

Include the following dependencies

  "com.google.maps" % "google-maps-services" % "0.1.17",
  "com.squareup.okhttp3" % "okhttp" % "3.6.0",
  "com.squareup.okio" % "okio" % "1.8.0"

Make use you have gson.jar version at least to be 2.3.1

Also make sure that Eclipse IDE compiles the correct version of these jar files other wise


java.lang.Error: Unresolved compilation problems:
The import com.google cannot be resolved
The import com.google cannot be resolved
The import com.google cannot be resolved
GeoApiContext cannot be resolved to a type
GeoApiContext cannot be resolved to a type
GeocodingResult cannot be resolved to a type
GeocodingApi cannot be resolved




package controllers;

import java.util.TimeZone;

import com.google.maps.GeoApiContext;
import com.google.maps.TimeZoneApi;
import com.google.maps.model.LatLng;

public class TimeZoneTest {
    
    private GeoApiContext context;
    
    public TimeZoneTest(GeoApiContext context) {
        this.context = context;
      }

    public static void main (String args[]) {
     
        try {
            GeoApiContext context = new GeoApiContext().setApiKey("google maps api key goes here");
            TimeZoneTest test = new TimeZoneTest (context);
            LatLng location = new LatLng(31.49822, 101.29795);
            TimeZone tz = TimeZoneApi.getTimeZone(test.context, location).await();
            System.out.println(tz.getDisplayName());
        }
        
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Output





More info about key generation can be found on - https://developers.google.com/maps/documentation/timezone/get-api-key



Resources
https://github.com/googlemaps/google-maps-services-java

No comments:

 Python Basics How to check the version of Python interpreter mac terminal

Popular in last 30 days