【问题标题】:android automatic title on red marker on Google Maps谷歌地图上红色标记上的android自动标题
【发布时间】:2014-02-12 02:38:59
【问题描述】:

我有一个 android 地图应用程序,它可以跟踪用户位置并将其显示在地图上。我这样做是为了在红色标记的顶部出现一个标题“你在这里”。但是,它并没有自己出现,我必须点击红色标记。我可以点击任何红色标记,标题会移到那里并消失在前一个标记上。

我如何让它只出现在最新的红色标记(最新位置)上并且不能被删除?向用户显示他的当前位置。

我设置的速度为1。我不知道它是否足够好。当我没有移动时,位置停止更新,但它仍然很慢且不准确。

    public void onLocationChanged(Location myLocation) {
    System.out.println("speed " + myLocation.getSpeed());
    if(myLocation.getSpeed() > speed)
    {
        //show location on map.................
        //Get latitude of the current location
        double latitude = myLocation.getLatitude();
        //Get longitude of the current location
        double longitude = myLocation.getLongitude();
        //Create a LatLng object for the current location
        LatLng latLng = new LatLng(latitude, longitude);
        //Show the current location in Google Map
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        //Zoom in the Google Map
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
        googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).snippet("You are here!").title("You are here!"));

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    试试这个:-

    Marker pos = googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).snippet("You are here!").title("You are here!"));
    

    而不是

       googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).snippet("You are here!").title("You are here!"));
    

    或者 写这个,很简单:-

    locationMarker.showInfoWindow();
    

    【讨论】:

    • 抱歉回复晚了。它有效,我添加 Marker pos = googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).sn-p("You are here!").title("You are here!")) ; pos.showInfoWindow();。它显示了我想要的。非常感谢
    • 没关系.. :) 很高兴.. :)
    【解决方案2】:

    如果不编写大量自定义视图和控件,您无法通过在 Android 上使用现有 API 来真正实现这一点。

    有一个不错的库,您可以使用它来自定义地图上的标记。这是取自其网站的示例。它被称为 android-maps-utils

    github 上的库链接。

    https://github.com/googlemaps/android-maps-utils

    还有网站,您可以在其中找到视频和其他示例。

    http://googlemaps.github.io/android-maps-utils/

    【讨论】:

      猜你喜欢
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 1970-01-01
      相关资源
      最近更新 更多