Map using Latitude/Longitude



Following is an example of a Map using Latitude/Longitude.

We have already seen the configurations used to draw a chart in Google Charts Configuration Syntax chapter. Now, let us see an example of a Map using Latitude/Longitude.

Example

HelloWorld.java

package com.tutorialspoint.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

import com.googlecode.gwt.charts.client.ChartLoader;
import com.googlecode.gwt.charts.client.ChartPackage;
import com.googlecode.gwt.charts.client.ColumnType;
import com.googlecode.gwt.charts.client.DataTable;
import com.googlecode.gwt.charts.client.map.Map;
import com.googlecode.gwt.charts.client.map.MapOptions;

public class HelloWorld implements EntryPoint {
   private Map chart;

   private void initialize() {
      ChartLoader chartLoader = new ChartLoader(ChartPackage.MAP);
      chartLoader.loadApi(new Runnable() {
         public void run() {
            // Create and attach the chart
            chart = new Map();
            RootPanel.get().add(chart);
            draw();
         }
      });
   }
   private void draw() {
      // Prepare the data
      DataTable data = DataTable.create();
      data.addColumn(ColumnType.NUMBER , "Latitude");
      data.addColumn(ColumnType.NUMBER, "Longitude");
      data.addColumn(ColumnType.STRING, "Name");

      data.addRow(37.4232, -122.0853, "Work");
      data.addRow(37.4289, -122.1697, "University");
      data.addRow(37.6153, -122.3900, "Airport");
      data.addRow(37.4422, -122.1731, "Shopping");
      
      // Set options
      MapOptions options = MapOptions.create();
      options.setShowTip(true);

      // Draw the chart
      chart.draw(data,options);
      chart.setWidth("400px");
      chart.setHeight("400px");
   }
   public void onModuleLoad() {
      initialize();
   }
}

Result

Verify the result.

Map Chart using Latitude/Longitude
gwt_googlecharts_maps.htm
Advertisements