Define an apiKey,
Hi I’m new to google maps and I need to define an api key, how can I do that ? and within and api key is it possible to test the application in local mode ?
thx
Define an apiKey,
Hi I’m new to google maps and I need to define an api key, how can I do that ? and within and api key is it possible to test the application in local mode ?
thx
I found the way on how to create it, I’m been hard coded now it for testing purpose but the map doesn’t display here is a screenshot.
I activate billing information to enable api key but the map is still doesn’t display. It’s been showing coordinates but not the map.
Solved by using the following code
private void buildGoogleMaps () {
String apiKey = “cccccccc”;
this.setSizeFull();
if (apiKey==null) {
add(new H2(“Api key is needded to run the demo, pass it using the following system property: ‘-Dgoogle.maps.api=’”));
} else {
GoogleMap gmaps = new GoogleMap(apiKey,null,null);
gmaps.setMapType(MapType.SATELLITE);
gmaps.setSizeFull();
gmaps.setCenter(new LatLon(-31.636036,-60.7055271));
gmaps.addMarker(“Center”, new LatLon(-31.636036,-60.7055271), true, “https://www.flowingcode.com/wp-content/uploads/2020/06/FCMarker.png”);
GoogleMapPolygon gmp = gmaps.addPolygon(Arrays.asList(
new GoogleMapPoint(gmaps.getCenter().getLat(),gmaps.getCenter().getLon()+1),
new GoogleMapPoint(gmaps.getCenter().getLat()+1,gmaps.getCenter().getLon()),
new GoogleMapPoint(gmaps.getCenter().getLat(),gmaps.getCenter().getLon()-1),
new GoogleMapPoint(gmaps.getCenter().getLat()-1,gmaps.getCenter().getLon())));
gmp.addClickListener(ev->Notification.show(“polygon clicked”));
Button center = new Button(“Show Coordinates”, ev-> {
Notification.show("Center coordinates: " + gmaps.getCenter());
});
Button addMarker = new Button(“Add Marker”, ev-> {
gmaps.addMarker(“New Marker”, gmaps.getCenter(), true, “”);
});
Button addPoint = new Button(“Add Polygon”, ev-> {
gmaps.addPolygon(Arrays.asList(new GoogleMapPoint(gmaps.getCenter()),
new GoogleMapPoint(gmaps.getCenter().getLat(),gmaps.getCenter().getLon()+1),
new GoogleMapPoint(gmaps.getCenter().getLat()+1,gmaps.getCenter().getLon())));
});
add(gmaps, new HorizontalLayout(center, addMarker, addPoint)); }
}