如何在黑莓应用程序中添加谷歌地图?
我正在做基于位置的项目,并且在他们提供的官方网站上,因为您不能使用 Google API。有没有其他方法可以代替下载地图并执行此操作?我可以将其重定向到谷歌地图吗?
如何在黑莓应用程序中添加谷歌地图?
我正在做基于位置的项目,并且在他们提供的官方网站上,因为您不能使用 Google API。有没有其他方法可以代替下载地图并执行此操作?我可以将其重定向到谷歌地图吗?
您只需将纬度和经度传递给以下代码。
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);