【问题标题】:how to send longitude and latitude to map application to show particular co-ordinates on map?如何将经度和纬度发送到地图应用程序以在地图上显示特定坐标?
【发布时间】:2012-09-17 22:17:16
【问题描述】:

我有一个应用程序,在该应用程序中,单击按钮、更改位置或特定时间后,我可以获得经度和纬度值。我想用这个值在谷歌地图应用程序上显示它们。我正在使用意图显示位置的地图打开地图,但不知何故它没有显示我得到的坐标。

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    这是我在我的一个应用程序中使用的一段工作代码。此代码还包括检查用户是否在他/她的设备上安装了 Google 地图。如果检查将应用程序返回为已安装,则该函数会将数据传递给应用程序。如果检查失败,它会显示一个 AlertDialog 通知用户未安装该应用程序。

    protected void showMap() {
    
        boolean installedMaps = false;
    
        // CHECK IF GOOGLE MAPS IS INSTALLED
        PackageManager pkManager = getPackageManager();
        try {
            @SuppressWarnings("unused")
            PackageInfo pkInfo = pkManager.getPackageInfo("com.google.android.apps.maps", 0);
            installedMaps = true;
        } catch (Exception e) {
            e.printStackTrace();
            installedMaps = false;
        }
    
        // SHOW THE MAP USING CO-ORDINATES FROM THE CHECKIN
        if (installedMaps == true) {
            String geoCode = "geo:0,0?q=" + PLACE_LATITUDE + ","
                    + PLACE_LONGITUDE + "(" + PLACE_NAME + ")";
            Intent sendLocationToMap = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(geoCode));
            startActivity(sendLocationToMap);
        } else if (installedMaps == false) {
    
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    CheckinsDetails.this);
    
            // SET THE ICON
            alertDialogBuilder.setIcon(R.drawable.ic_launcher);
    
            // SET THE TITLE
            alertDialogBuilder.setTitle("Google Maps Not Found");
    
            // SET THE MESSAGE
            alertDialogBuilder
                    .setMessage(R.string.noMapsInstalled)
                    .setCancelable(false)
                    .setNeutralButton("Got It",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    dialog.dismiss();
                                }
                            });
    
            // CREATE THE ALERT DIALOG
            AlertDialog alertDialog = alertDialogBuilder.create();
    
            // SHOW THE ALERT DIALOG
            alertDialog.show();
        }
    }
    

    下面提到的这行代码将其发送到谷歌地图,而不是只显示 Pin 还显示位置名称。

    String geoCode = "geo:0,0?q=" + PLACE_LATITUDE + ","
                        + PLACE_LONGITUDE + "(" + PLACE_NAME + ")";
    

    编辑:如果您不想显示 PLACE_NAME,请修改该特定行:geo:latitude,longitude,而不是代码块中使用的那一行。 p>

    查看此链接以了解更多可能的组合,例如 zoom,例如:http://developer.android.com/guide/appendix/g-app-intents.html

    【讨论】:

    • @PrashantRane:很高兴能帮上忙。 :-)
    【解决方案2】:
    Double latitud = 37.40*1E6;
                Double longitud = -5.99*1E6;
    
                GeoPoint loc =
                    new GeoPoint(latitud.intValue(), longitud.intValue());
    
                controlMapa.animateTo(loc);
    
                int zoomActual = mapa.getZoomLevel();
    
                for(int i=zoomActual; i<10; i++)
                    controlMapa.zoomIn();
            }
    

    在哪里

     controlMapa = mapa.getController();
    
          mapa = (MapView)findViewById(R.id.linearLayout1);
    

    欲了解更多信息:MapView Tutorial

    【讨论】:

    • 我没有为显示地图编写代码,但想将坐标发送到我们在每个安卓手机上获得的现有地图应用程序......
    • ¬¬' 是的,我知道.... controlMapa.animateTo(loc);当 loc 是位置时......它与@Siddharth Lele 的代码相同,但更简单的方法......取决于你......
    【解决方案3】:

    试试这个:

    String url = "http://maps.google.com/maps?daddr="+ ze.getCoordenada().getLatitude() + ","+     ze.getCoordenada().getLongitude();
    Intent goZe = new Intent(Intent.ACTION_VIEW);
    goZe.setData(Uri.parse(url));
    startActivity(goZe);
    

    您将收到使用浏览器或地图的提示

    【讨论】:

      【解决方案4】:

      不知何故,在谷歌上使用这个字符串

      String url = "http://maps.google.com/maps?daddr="+ ze.getCoordenada().getLatitude() + ","+     ze.getCoordenada().getLongitude();
      

      在选择谷歌地图时显示相反的经度和纬度,而网站是正确的。

      也许我使用的是旧版本的谷歌地图

      【讨论】:

        【解决方案5】:
        public void showMap(long latitude, long longitude) {
            String geoCode = "geo:0,0?q=" + latitude + ","
                                + longitude;
            Intent sendLocationToMap = new Intent(Intent.ACTION_VIEW, Uri.parse(geoCode));
            if (sendLocationToMap.resolveActivity(getPackageManager())!=null){
                startActivity(sendLocationToMap);
            }
            else {
                Toast.makeText(this,"No Application To handle the Request",Toast.LENGTH_SHORT).show();
            }
        }
        

        【讨论】:

          猜你喜欢
          • 2012-01-04
          • 2011-10-31
          • 1970-01-01
          • 2018-08-08
          • 2014-01-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多