2

我刚刚让我的地图在我的应用程序中工作。我有问题。当这个地方出现在地图上时。我希望能够单击该地点并将其显示在适当的 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;
 }

} 

这可能吗?

更多信息:我想点击我的应用程序中显示的标记。单击标记后,它将转到谷歌地图并根据需要定向到它。

4

2 回答 2

3

如果我理解正确,您想要的是向 Google Maps 应用程序发送带有纬度和经度的意图,以便用户可以导航到特定位置。这是我在我的应用程序中实现它的方式:

Intent navigation = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" +latlong.latitude+","+latlong.longitude));
        startActivity(navigation);

latlong 是 LatLng 类型。

更新 1 - 收听标记上的点击

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;
}

} 
于 2013-09-03T14:30:46.650 回答
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;
}
于 2013-09-03T14:53:52.353 回答