繁体   English   中英

谷歌地图Android Studio

[英]Google maps Android Studio

好吧,我实际上在做一个应用程序,但我不知道如何继续。

我希望google map能够接受300米范围内的所有站点,并通过餐厅,商店等服务对站点进行分类。

你知道怎么做吗? 这是我的代码:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng marker = new LatLng(0, 0);
        mMap.addMarker(new MarkerOptions().position(marker).title("Marker"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(marker));
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        mMap.setMyLocationEnabled(true);

    }

}

您需要使用Google的Place Search API。 首先,您需要调用Google附近的搜索API-

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=300&key=YOUR_API_KEY

您将获得以下格式的JSON响应-

{
  "html_attributions": [],
  "results": [
    {
      "geometry": {
        "location": {
          "lat": -33.870775,
          "lng": 151.199025
        }
      },
      "icon": "",
      "id": "",
      "name": "Rhythmboat Cruises",
      "place_id": "ChIJyWEHuEmuEmsRm9hTkapTCrk",
      "types": [
        "travel_agency",
        "restaurant",
        "food",
        "establishment"
      ],
      "vicinity": "Pyrmont Bay Wharf Darling Dr, Sydney"
    }
  ],
  "status": "OK"
}

然后,您可以解析此JSON响应并获取所需的信息。

您可以在https://developers.google.com/places/web-service/search上找到更多相关信息。

或者,您可以尝试以下教程-https: //www.androidtutorialpoint.com/intermediate/google-maps-search-nearby-displaying-nearby-places-using-google-places-api-google-maps-api- v2 /

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM