Google Map MapView 使用意图按钮进行地理编码 - 未通向正确的位置
我已经设置了一个具有叠加层的 MapView 类(并且它们工作正常。)
我的应用程序是围绕选项卡构建的,在我的第一个选项卡上,这是我的代码:
public void onCreate(Bundle savedInstanceState) {
Button ButtonName1;
Button ButtonName2;
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
{
ButtonName1 = (Button) findViewById(R.id.ButtonName1);
ButtonName1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:51.594748,-0.107879"));
i.setClassName("my.android.project", "my.android.project.Map"); // .Map is my MapView file
startActivity(i);
}
});
}
{
ButtonName2 = (Button) findViewById(R.id.ButtonName2);
ButtonName2_Cinema.setOnClickListener(new OnClickListener() {
public void onClick(View arg1) {
Intent ii = new Intent(Intent.ACTION_VIEW, Uri.parse("51.55748,0.07388"));
ii.setClassName("my.android.project", "my.android.project.Map");
startActivity(ii);
}
});
}
}
}
现在,通过单击这些按钮,它成功引导我进入地图类和我的叠加层显示得非常好,位于正确的位置,但它并没有向我指出那些确切的纬度和经度位置,因此,不能直接指向叠加层。
有谁知道为什么?
这是我的地图类:
公共类 Map 扩展 MapActivity {
private MapView mapView;
public static int latitude1 = (int) (51.508170 * 1E6);
public static int longitude1 = (int) (-0.128017 * 1E6);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
OverlayMap itemizedOverlay = new OverlayMap(drawable, this);
GeoPoint location1 = new GeoPoint(latitude1, longitude1);
OverlayItem overlayitem = new OverlayItem(location1, "Title", "Contents");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
MapController mapController = mapView.getController();
GeoPoint yourGeoPoint = new GeoPoint(latitude1,longitude1);
mapController.animateTo(yourGeoPoint);
mapController.setZoom(10);
}
@Override
protected boolean isRouteDisplayed() {
return true;
}
}
I have set up a MapView Class which has Overlays (and they're working fine.)
My application is built around tabs and on my first tab, this is my code:
public void onCreate(Bundle savedInstanceState) {
Button ButtonName1;
Button ButtonName2;
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
{
ButtonName1 = (Button) findViewById(R.id.ButtonName1);
ButtonName1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:51.594748,-0.107879"));
i.setClassName("my.android.project", "my.android.project.Map"); // .Map is my MapView file
startActivity(i);
}
});
}
{
ButtonName2 = (Button) findViewById(R.id.ButtonName2);
ButtonName2_Cinema.setOnClickListener(new OnClickListener() {
public void onClick(View arg1) {
Intent ii = new Intent(Intent.ACTION_VIEW, Uri.parse("51.55748,0.07388"));
ii.setClassName("my.android.project", "my.android.project.Map");
startActivity(ii);
}
});
}
}
}
Now by clicking on those buttons, it successfully leads me onto the Map class and my overlays are displayed perfectly well, in the correct position, but it doesn't point me to that those exact latitude and longitude positions, therefore, not directly onto the overlays.
Does anyone know why?
Here's my MapClass:
public class Map extends MapActivity {
private MapView mapView;
public static int latitude1 = (int) (51.508170 * 1E6);
public static int longitude1 = (int) (-0.128017 * 1E6);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
OverlayMap itemizedOverlay = new OverlayMap(drawable, this);
GeoPoint location1 = new GeoPoint(latitude1, longitude1);
OverlayItem overlayitem = new OverlayItem(location1, "Title", "Contents");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
MapController mapController = mapView.getController();
GeoPoint yourGeoPoint = new GeoPoint(latitude1,longitude1);
mapController.animateTo(yourGeoPoint);
mapController.setZoom(10);
}
@Override
protected boolean isRouteDisplayed() {
return true;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用 animateTo(GeoPoint geoPoint) 方法前往您的地理位置?
编辑:
你必须在你的MapActivity中做这样的事情,你可以把代码放在onCreate()中:
我不知道你的MapActivity到底如何帮助你更好,但问题是你必须将上面的代码放在 MapActivity 中,您可以在其中访问地图控制器和新坐标(我认为在 onCreate() 中)。
编辑二:
我认为您没有通过您的意图正确发送经度和纬度。
您必须使用 Bundle 才能做到这一点。请阅读这篇文章了解更多信息详细信息..
编辑 III:
好的,所以您应该这样做以将您的地理点传递到下一个活动:
在您的按钮单击侦听器中,您应该这样写:
好的,现在我们必须从包中获取数据并在您的地图上使用它。以下代码适用于 onCreate() 方法中的 MapActivity:
ButtonActivity 是其上的活动你有按钮:)。请注意,您必须在捆绑包中使用相同的密钥字符串才能获取正确的数据,就像上面的示例一样。
我希望现在一切都清楚了:D。
Are you using
animateTo(GeoPoint geoPoint)
method to go to your geo point?EDIT:
You have to do something like this in your MapActivity, you can put the code in onCreate():
I don't know exactly how is your MapActivity to help you better but the thing is that you have to put the code above in the MapActivity where you have access to your map controler and the new coordinates (I think in onCreate() ).
EDIT II :
I think you are not sending correctly the longitude and latitude through your intent.
You have to make use of a Bundle to do that. Please read this article for more details..
EDIT III :
Ok so you should do this to pass your geopoints to the next activity:
In your button click listener you should write this:
Ok so now we have to get the data from the bundle and use it on your map.. The following code is for your MapActivity in onCreate() method:
The ButtonActivity is the activity on which you have the buttons :). Note that you have to use the same key strings in your bundle to get the correct data, just like in the example above.
I hope now everything is clear :D.