如何通过SWT执行google map api

时间:2014-03-05 02:56:44

标签: javascript css google-maps swt

我想在google地图上做一个标记,latlng是已知的,如何获取地址并在google地图中显示,我需要一个桌面应用程序(RCP),我已经执行了eclipse,我可以得到满意的结果。     `import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class BrowserTest {

    public static void main(String[] args) {
    File f = new File("F:/Javawork/EclipseWork/mapother/map7.html");
    final Display display = Display.getDefault();
    final Shell shell = new Shell();
    //shell.setSize(327, 253);
    shell.setSize(981, 759);
    // 
    shell.setLayout(new FillLayout());
    Browser browser = new Browser(shell, SWT.NONE);
    browser.setUrl(f.toURI().toString());

    //browser.execute("var arr = new Array(31.28794,121.475372)");
    //browser.execute("var lat = parseFloat(arr[0]);\r\n"
    //              + "var lng = parseFloat(arr[1]);\r\n"
    //              + "var latlng = new google.maps.LatLng(lat, lng);\r\n");
    //browser.execute("alert('latlng' + latlng);");
    browser.execute("geocoder.geocode({'latLng': 31.28794,121.475372}, function(results, status){"
            + "infowindow.setContent(results[1].formatted_address);"
            + "infowindow.open(map, new google.maps.Marker({position: latlng,map: map}));"
            + "})");
    //browser.execute("{};");
    browser.execute("alert('lat' + lat + ';'+'lng' + lng);");

    //browser.execute(" map.setCenter(results[0].geometry.location);");
    //browser.execute("var marker = new google.maps.Marker({map: map, position: results[0].geometry.location });");
    // -----------------END------------------------
    shell.layout();
    shell.open();
    while (!shell.isDisposed()) { 
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

}

`

<html>
  <head>
   <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"
  src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAsKYbMVVMZxnbXeCYzYCN5FJJTA6GE1L4&sensor=true">
</script>
<script type="text/javascript">
  var map;
function initialize() 
{

        map = new google.maps.Map(document.getElementById("map_canvas"));
        InitComplete();
        google.maps.event.addListener(map,"click", function(overlay,latlng) 
        {     
            NotifyAddMarker(latlng.lat(), latlng.lng());
        });

}

</script>

          

0 个答案:

没有答案