我正在製作一個應用程序,當他們從導航抽屜中選擇「定位」選項時,會讓別人查找附近的醫生(在Google地圖上註冊)。運行谷歌地圖API搜索查詢
我已經得到了谷歌地圖的片段,並已初始化爲當前加載特定的經度和緯度,並添加了一個位置按鈕指向用戶的當前位置。
但是,我想要做的是,當某人從導航抽屜中選擇「定位」選項時,應用程序應該自動加載用戶的當前位置,並向其顯示5米半徑。
我是新來編碼,所以我不知道它是如何編碼!
這是我目前的fragment.java文件
package com.test.drawernav;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
/**
* A simple {@link Fragment} subclass.
*/
public class LocateFragment extends Fragment implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
public LocateFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View mapView = inflater.inflate(R.layout.fragment_locate, container, false);
return mapView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SupportMapFragment mapFragment = (SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onConnectionFailed(ConnectionResult arg0){
}
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.6139, 77.2090), 12.0f));
// googleMap.setMyLocationEnabled(true);
}
}
可能的重複 - http://stackoverflow.com/questions/32393134/getting-results-of-nearby-places-from-users-location-using-google-maps-api-in-a – adjuremods