在面试前我已经给出了这个练习来创建一个小应用程序。 在应用程序的某个位置,我需要使用纬度和经度坐标在地图上显示一个位置。在不使用谷歌地图的情况下显示地图上的位置
但我认为我不应该使用Google Maps API,而是使用设备上的“内置”地图。
有这样的事吗? 是否有一个简单的MapView视图,我可以在我的布局中接受纬度和经度坐标,并在正确的位置放置一个标记?
我一直在寻找一个教程,解释如何在Android上使用内置的地图API,但找不到一个。
任何帮助,将不胜感激。
在面试前我已经给出了这个练习来创建一个小应用程序。 在应用程序的某个位置,我需要使用纬度和经度坐标在地图上显示一个位置。在不使用谷歌地图的情况下显示地图上的位置
但我认为我不应该使用Google Maps API,而是使用设备上的“内置”地图。
有这样的事吗? 是否有一个简单的MapView视图,我可以在我的布局中接受纬度和经度坐标,并在正确的位置放置一个标记?
我一直在寻找一个教程,解释如何在Android上使用内置的地图API,但找不到一个。
任何帮助,将不胜感激。
通常在这些代码挑战面试时,他们想看看你能在相对较短的时间内想出什么。
与@bwegs提到的类似,你应该向面试官询问是否有任何限制。我已经做了很多面试,其中的代码挑战是在24小时内创建一些东西,但应用程序的大小只是大到完成。在这种情况下,我会利用第三方库。
我不知道检索地图,所以如果你可以使用谷歌地图API,比我想先在这里阅读文档https://developers.google.com/maps/documentation/android/
而且你可以利用谷歌静态地图API https://developers.google.com/maps/documentation/staticmaps/的启动任何其他方法这将返回特定位置的静态图像。
这里是我创建得到一个谷歌静态地图
class CreateStaticMapAsyncTask extends AsyncTask<String, Void, Bitmap> {
private static final String STATIC_MAPS_API_BASE = "https://maps.googleapis.com/maps/api/staticmap";
private static final String STATIC_MAPS_API_SIZE = "500x500";
@Override
protected void onPreExecute() {
addTask(); // adds one to task count.
super.onPreExecute();
}
@Override
protected Bitmap doInBackground(String... params) {
// TODO Auto-generated method stub
locationString = params[0];
Bitmap bmp = null;
StringBuilder sb = new StringBuilder(STATIC_MAPS_API_BASE);
try {
sb.append("?center=").append(
URLEncoder.encode(locationString, "UTF-8"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
sb.append("&size=" + STATIC_MAPS_API_SIZE);
sb.append("&key=" + API_KEY);
String url = new String(sb.toString());
Log.e("URL", sb.toString());
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
InputStream in = null;
try {
in = httpclient.execute(request).getEntity().getContent();
bmp = BitmapFactory.decodeStream(in);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return bmp;
}
protected void onPostExecute(Bitmap bmp) {
super.onPostExecute(bmp);
if (bmp != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
data = stream.toByteArray();
removeTask();
allTasksComplete();
}
}
}
可与该电话new CreateStaticMapAsyncTask().execute(loc);
,你可以检索例如当前位置,像这样(被访问的一般的AsyncTask不是唯一的方式)
LocationManager locManager = (LocationManager) getActivity()
.getSystemService(Context.LOCATION_SERVICE);
boolean network_enabled = locManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Location location;
if (network_enabled) {
location = locManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
_longitude = location.getLongitude();
_latitude = location.getLatitude();
etLocation.setText(_latitude + "," + _longitude);
}
}
当今Android设备上的“内置”地图是谷歌地图。毕竟,Android = Google。我无法想象为什么有人会试图让你做这个而不是某种API,但这是另一回事。
不要害怕与面试官(或者给你这个练习的人)核实你是否可以使用谷歌地图API - 这是一个非常重要的细节,可以让你的生活变得非常重要更轻松。
好的,谢谢你的提示! – 2015-03-13 20:40:02
感谢ItzHoudini。我想我会使用Google Maps API。这是一个初学者的位置,所以我想他们希望我使用标准方法。我只是觉得还有另一种流行的做法。 – 2015-03-13 20:45:42
我从您提供的链接中的指南了解到,我必须注册我的应用以获取使用Google Maps API的API密钥。但我甚至不发布应用程序。这只是一个练习。这真的是唯一的选择吗? – 2015-03-13 21:25:08
我相信你不得不使用API密钥。 Google Maps API V3不需要密钥,但仅适用于Javascript。您应该了解如何检索SHA1指纹,并设置Google Developer Console帐户。理解您所看到的内容需要一点时间,但是值得,因为在您的职业生涯中您会遇到多个Google API。 – 2015-03-14 01:45:19