如何在谷歌地图中实际显示项目的位置?
我有一个谷歌地图应用程序,显示两个项目(itemizedoverlay 类),并且我有一个更新按钮。当我按下更新按钮时,我想从地图中删除项目,并再次放置相同的项目,但具有新的纬度和经度值(我有一项服务,可以实现共享首选项中的纬度和经度字段,并且我也通过捆绑重新获得其他位置)
我做错了什么?当我尝试我的代码时,地图的项目不会被删除......只是出现新项目......但我想删除旧的项目
updateButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mapOverlays.clear();
updateMyPosition();
updateFriendPosition();
}
});
,这是我的两个功能:
private void updateFriendPosition()
{
Bundle bundle = this.getIntent().getExtras();//get the intent & bundle passed by X
userText.setText(bundle.getString("user"));
permissionText.setText(bundle.getString("permission"));
lastUpdateText.setText(bundle.getString("lastupdate"));
String coordinates[] = {bundle.getString("lat"), bundle.getString("lon")};
lat = Double.parseDouble(coordinates[0]);
lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
OverlayItem overlayitem1 = new OverlayItem(p, bundle.getString("user"), "Hi Friend!");
itemizedoverlay.addOverlay(overlayitem1);
mapOverlays.add(itemizedoverlay);// dibujo la estrella con la posicion actual del friend
mc.animateTo(p); ///nos centra el mapa en la posicion donde esta nuestro amigo
mc.setZoom(10); /// ajusta el zoom a 10
}
private void updateMyPosition()
{
String coordinates[] = {settings.getString("mylatitude", null),settings.getString("mylongitude", null)};
lat = Double.parseDouble(coordinates[0]);
lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
OverlayItem overlayitem1 = new OverlayItem(p, "Me", "My Position");
itemizedoverlay2.addOverlay(overlayitem1);
mapOverlays.add(itemizedoverlay2);//dibujo mi icono para mostrarme a mi
}
我还尝试了 invalidate()地图视图,但它不起作用...仍然绘制旧项目...
i have a googlemap app that displays two items (itemizedoverlay class) and i have a Update button. When i press the update button, i want to remove the items from the map, and put again the same items but with the new latitude and longitude values (i have a service that actualice the latitude and longitude fields that i have in sharedPreferences, and also i recibe the other position by a bundle)
what i am doing wrong? when i try my code, the items of the map doesn't be removed.... just new items appear... but i want to remove the old ones
updateButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mapOverlays.clear();
updateMyPosition();
updateFriendPosition();
}
});
and these are my two functions:
private void updateFriendPosition()
{
Bundle bundle = this.getIntent().getExtras();//get the intent & bundle passed by X
userText.setText(bundle.getString("user"));
permissionText.setText(bundle.getString("permission"));
lastUpdateText.setText(bundle.getString("lastupdate"));
String coordinates[] = {bundle.getString("lat"), bundle.getString("lon")};
lat = Double.parseDouble(coordinates[0]);
lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
OverlayItem overlayitem1 = new OverlayItem(p, bundle.getString("user"), "Hi Friend!");
itemizedoverlay.addOverlay(overlayitem1);
mapOverlays.add(itemizedoverlay);// dibujo la estrella con la posicion actual del friend
mc.animateTo(p); ///nos centra el mapa en la posicion donde esta nuestro amigo
mc.setZoom(10); /// ajusta el zoom a 10
}
private void updateMyPosition()
{
String coordinates[] = {settings.getString("mylatitude", null),settings.getString("mylongitude", null)};
lat = Double.parseDouble(coordinates[0]);
lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
OverlayItem overlayitem1 = new OverlayItem(p, "Me", "My Position");
itemizedoverlay2.addOverlay(overlayitem1);
mapOverlays.add(itemizedoverlay2);//dibujo mi icono para mostrarme a mi
}
i also tryed with invalidate() on the mapview but it doesn't works... still paint the old items...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这是基于SDK教程的。您已向 itemizedoverlay 添加了两件事,另一件事是。需要在HelloItemizedOverlay中添加一个方法,即 'clear'
调用前调用该方法
It looks like this is based on the SDK tutorial. You've added two things to itemizedoverlay and the other one. You need to add a method in HelloItemizedOverlay, namely 'clear'
Call this method before you call