Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何导航地图(Android地图API v2)_Android_Google Maps_Google Maps Api 2 - Fatal编程技术网

如何导航地图(Android地图API v2)

如何导航地图(Android地图API v2),android,google-maps,google-maps-api-2,Android,Google Maps,Google Maps Api 2,我刚在我的应用程序中使用了我的地图。我有点问题。当这个地方出现在地图上时。我希望能够点击这个地方,让它在适当的谷歌地图应用程序中显示出来。因此,如果需要,您可以导航到该位置 所以我有一张地图,上面有一个标记。我想点击标记,然后在谷歌地图上找到地址。这样,如果人们想要导航,他们只需点击它,然后就能知道方向 java代码如下所示: public class showroommap extends Activity { static final LatLng HAMBURG = new LatLng(

我刚在我的应用程序中使用了我的地图。我有点问题。当这个地方出现在地图上时。我希望能够点击这个地方,让它在适当的谷歌地图应用程序中显示出来。因此,如果需要,您可以导航到该位置

所以我有一张地图,上面有一个标记。我想点击标记,然后在谷歌地图上找到地址。这样,如果人们想要导航,他们只需点击它,然后就能知道方向

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

} 
这可能吗

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

如果我理解正确,您想要的是向谷歌地图应用程序发送一份带有纬度和经度的意图,以便用户可以导航到特定位置。以下是我如何在我的应用程序中实现它:

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

} 

这里也许你可以用这样的东西

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

嗨,是的,我有点想在我的应用程序中打开地图。但是当我点击标记时,我希望它转到地图并显示方向是的,所以你要做的是设置GoogleMap.setOnMarkerClickListener();然后在onMarkerClick(Marker-Marker)上设置并启动意图。您可以通过使用if语句并将传递给方法的标记的标题与您提供给标记的名称标题相匹配,或者通过使用Marker.equals(kiel)简单地测试标记是否是相同的标记,来引用Marker click(Marker Marker Marker)中的特定标记。例如。嗨,ank非常适合您的响应。。。这里有一篇我发现的关于实现的帖子。我将编辑我的答案以帮助您。如果这个问题解决了您的问题,请将此问题标记为已回答。他希望能够单击标记并让标记启动Google Maps应用程序…而不是Google Maps、Google navigator,以及用于插入标记单击的just alert对话框,我在考虑把它脱下来,他说这不是你想要的。现在开始,我在我的回答
public boolean onMarkerClick(Marker arg0)中编辑了你的问题作为一个工作示例{
error表示它必须是布尔值。如果我将其更改为布尔值,则表示它必须为void。因此,它循环或表示添加返回语句。您应该删除javascript标记,因为此问题与javascript无关。