【发布时间】:2012-04-02 13:16:41
【问题描述】:
我需要在针对黑莓操作系统 6.0 开发的应用程序中使用 Bing 地图。但找不到任何本机可用的框架或 SDK。请帮助我在黑莓上使用 Bing 或 Google Maps SDK。请提供我可以从中获取 SDK 的参考资料。谢谢。
【问题讨论】:
标签: blackberry bing-maps
我需要在针对黑莓操作系统 6.0 开发的应用程序中使用 Bing 地图。但找不到任何本机可用的框架或 SDK。请帮助我在黑莓上使用 Bing 或 Google Maps SDK。请提供我可以从中获取 SDK 的参考资料。谢谢。
【问题讨论】:
标签: blackberry bing-maps
这里是一个使用谷歌地图的例子,不知道怎么用必应地图。
首先,通过在设备/模拟器的浏览器上点击此链接,从http://m.google.com/maps/ 在您的设备/模拟器上安装 Google 地图。
然后,您可以从您的应用程序调用 Google Maps 应用程序。这是一个代码示例:
package mypackage;
import net.rim.blackberry.api.browser.URLEncodedPostData;
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.ApplicationManagerException;
import net.rim.device.api.system.CodeModuleManager;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class MyScreen extends MainScreen
{
/**
* Creates a new MyScreen object
*/
public MyScreen()
{
// Set the displayed title of the screen
setTitle("Google Maps");
VerticalFieldManager mainManager = new VerticalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH);
final BasicEditField latitudeInputField = new BasicEditField("Latitude:" , "23.717782");
final BasicEditField longitudeInputField = new BasicEditField("Longitude:" , "90.407124");
final BasicEditField titleInputField = new BasicEditField("Title:" , "Dhaka, Bangladesh");
final BasicEditField descriptionInputField = new BasicEditField("Description:" , "Capital City of Bangladesh");
ButtonField btn_ShowMap = new ButtonField("Show On Map");
btn_ShowMap.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
double lat = Double.parseDouble( latitudeInputField.getText() );
double lon = Double.parseDouble( longitudeInputField.getText() );
String title = titleInputField.getText();
String description = descriptionInputField.getText();
showGoogleMap(lat, lon, title, description);
}
});
mainManager.add(latitudeInputField);
mainManager.add(longitudeInputField);
mainManager.add(titleInputField);
mainManager.add(descriptionInputField);
mainManager.add(btn_ShowMap);
add(mainManager);
}
/**
* Starts the Google Maps application and the specified locatin is shown on map
* @param latitude the latitude of the location to show
* @param longitude the longitude of the location to show
* @param title the title of the location to show
* @param description the description of the location to show
*/
public void showGoogleMap(double latitude, double longitude, String title, String description) {
try {
int mh = CodeModuleManager.getModuleHandle("GoogleMaps");
if (mh == 0) {
throw new ApplicationManagerException("GoogleMaps isn't installed");
}
URLEncodedPostData uepd = new URLEncodedPostData(null, false);
uepd.append("action","LOCN");
uepd.append("a", "@latlon:"+latitude+","+longitude);
uepd.append("title", title);
uepd.append("description", description);
String[] args = { "http://gmm/x?"+uepd.toString() };
ApplicationDescriptor ad = CodeModuleManager.getApplicationDescriptors(mh)[0];
ApplicationDescriptor ad2 = new ApplicationDescriptor(ad, args);
ApplicationManager.getApplicationManager().runApplication(ad2, true);
} catch(final Exception excp) {
Dialog.alert("Sorry, can't start Google Map: " + excp.getMessage());
}
}
}
它应该是这样的:
我只在模拟器 9800 (OS 6) 上测试过
【讨论】:
检查Nutiteq RIM BlackBerry Mapping SDK。
您可以从 Bing Maps、Yahoo! 获取地图内容地图、OpenStreetMap 等等。通过Nutiteq BlackBerry mapping SDK tutorial 开始编码。
【讨论】: