我只是让我的地图在我的应用中运行。我遇到了问题。当地方出现在地图上时。我希望能够点击该地点并将其显示在正确的Google地图应用中。所以,如果需要,你可以导航到这个地方。
所以我有一张地图上有标记的地方。我想点击标记,然后在Google地图中显示地址。这样,如果人们要导航,他们只需点击它然后获取路线。
java代码如下:
public class showroommap extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(52.633011,-1.132913);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showroommap);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
//Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
//Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
这可能吗?
更多信息: 我想点击我的应用程序中显示的标记。点击标记后,它将转到谷歌地图,并根据需要指向它。
答案 0 :(得分:3)
如果我理解正确您想要的是向谷歌地图应用程序发送具有纬度和经度的意图,那么用户可以导航到特定的位置。以下是我在我的应用中实现它的方式:
Intent navigation = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" +latlong.latitude+","+latlong.longitude));
startActivity(navigation);
latlong是LatLng类型。
更新1 - 收听Marker点击
public class showroommap extends Activity implements onMarkerClickListener {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(52.633011,-1.132913);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showroommap);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
map.setOnMakerClickListener(this); //Register this Activity to the onMarkerClickListener
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
//Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
//Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(kiel))
{
//handle click here
return true;
}
else if (marker.equals(hamburg))
{
//handle click here
return true;
}
return false;
}
}
答案 1 :(得分:0)
这里也许你可以使用这样的东西
public class showroommap extends Activity implements OnMarkerClickListener{
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(52.633011,-1.132913);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showroommap);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
map.setOnMarkerClickListener(this);
//Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
//Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
@Override
public boolean onMarkerClick(Marker arg0) {
final Context mContext = this;
final LatLng now = arg0.getPosition();
AlertDialog.Builder course = new AlertDialog.Builder(mContext);
course.setNegativeButton("On Foot", new OnClickListener(){
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("google.navigation:ll=%s,%s%s", now.latitude, now.longitude, "&mode=w")));
mContext.startActivity(i);
}
});
course.setNeutralButton("By Car", new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("google.navigation:ll=%s,%s%s", now.latitude, now.longitude, "&mode=d")));
mContext.startActivity(i);
}
});
course.setPositiveButton("On Bike", new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("google.navigation:ll=%s,%s%s", now.latitude, now.longitude, "&mode=b")));
mContext.startActivity(i);
}
});
course.show();
return false;
}