如何在Blackberry应用程序中添加谷歌地图?

时间:2013-03-15 06:05:30

标签: google-maps blackberry

如何在Blackberry应用程序中添加谷歌地图?

我正在进行基于位置的项目,并在官方网站上提供 您无法使用Google API 。有没有其他方法而不是下载地图并这样做?我可以将其重定向到谷歌地图吗?

1 个答案:

答案 0 :(得分:1)

您只需将纬度和经度传递给以下代码即可。

    StringBuffer html;
    String initial = "<!DOCTYPE html>\r\n" +
    "<html> \r\n" +
    "<head> \r\n" +
    "  <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" /> \r\n" +
    "  <title>Google Maps Multiple Markers</title> \r\n" +
    "  <script src=\"http://maps.google.com/maps/api/js?sensor=true\" \r\n" +
    "          type=\"text/javascript\"></script>\r\n" +
    "</head> \r\n" +
    "<body>\r\n" +
    "  <div id=\"map\" style=\"width: 343px; height: 385px;\"></div>\r\n" +
    "\r\n" +
    "  <script type=\"text/javascript\">\r\n" +
    "    var locations = [";
    String second= " ];\r\n" +
    "\r\n" +
    "    var map = new google.maps.Map(document.getElementById('map'), {\r\n" +
    "      zoom: 8,";
    String centerPoint ="";
    String finalpart = " mapTypeId: google.maps.MapTypeId.ROADMAP\r\n" +
    "    });\r\n" +
    "\r\n" +
    "    var infowindow = new google.maps.InfoWindow();\r\n" +
    "\r\n" +
    "    var marker, i;\r\n" +
    "\r\n" +
    "    for (i = 0; i < locations.length; i++) {  \r\n" +
    "      marker = new google.maps.Marker({\r\n" +
    "        position: new google.maps.LatLng(locations[i][1], locations[i][2]),\r\n" +
    "        map: map\r\n" +
    "      });\r\n" +
    "\r\n" +
    "      google.maps.event.addListener(marker, 'click', (function(marker, i) {\r\n" +
    "        return function() {\r\n" +
    "          infowindow.setContent(locations[i][0]);\r\n" +
    "         \r\n" +
    "        }\r\n" +
    "      })(marker, i));\r\n" +
    "    }\r\n" +
    "  </script>\r\n" +
    "</body>\r\n" +
    "</html>";
    html=new StringBuffer();
    html.append(initial);

        String point = "['"+""+"',"+lattitude+","+longitude+","+""+"],";

        html.append(point);
    centerPoint = "  center: new google.maps.LatLng("+lattitude+","+longitude+"),";
    html.append(second);
    html.append(centerPoint);
    html.append(finalpart);
    BrowserFieldConfig _bfConfig = new BrowserFieldConfig();        
      _bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
      _bfConfig.setProperty( BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
  _bfConfig.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");
  BrowserField myBrowserField = new BrowserField(_bfConfig);
  myBrowserField.displayContent(html.toString(), "");
  HorizontalFieldManager horf=new HorizontalFieldManager(HORIZONTAL_SCROLL);
  horf.add(myBrowserField);
  add(horf);