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谷歌地图标记从Firebase中的地址获取纬度和经度_Android_Google Maps_Geocoding - Fatal编程技术网

Android谷歌地图标记从Firebase中的地址获取纬度和经度

Android谷歌地图标记从Firebase中的地址获取纬度和经度,android,google-maps,geocoding,Android,Google Maps,Geocoding,我想知道是否有可能从地址中获得纬度和经度。我读到我可以使用地理编码器将地址转换为Lat和Long 但是,我不知道如何实现这一点,因为我正在手动存储位置的地址、lat和long,并从firebase检索它。我正在通过坐标在地图上添加标记。但我想要的是从地址中获取坐标,而不是手动输入坐标。我是否在检索地址的部分下添加Geocoder功能?我该怎么做 这就是我读到的例子: LocationTransmitActivity.java public class LocationRemitActivit

我想知道是否有可能从地址中获得纬度和经度。我读到我可以使用地理编码器将地址转换为Lat和Long

但是,我不知道如何实现这一点,因为我正在手动存储位置的地址、lat和long,并从firebase检索它。我正在通过坐标在地图上添加标记。但我想要的是从地址中获取坐标,而不是手动输入坐标。我是否在检索地址的部分下添加
Geocoder
功能?我该怎么做

这就是我读到的例子:

LocationTransmitActivity.java

 public class LocationRemitActivity extends FragmentActivity implements OnMapReadyCallback {
        public static final String EXTRA_NAME = "";
        private static final String TAG = "tag";
        private ClusterManager<StoreLatLng> mClusterManager;
        private GoogleMap mMap;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_remit_location);

            ButterKnife.bind(this);

            // Obtain the SupportMapFragment and get notified when the map is ready to be used.
            SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(map);
            mapFragment.getMapAsync(this);


        }

        @Override
        public void onMapReady(GoogleMap googleMap) {
            mMap = googleMap;
            // Marker Cluster
            setUpClusterer();
            mMap.getUiSettings().setIndoorLevelPickerEnabled(false);
        }

        private void setUpClusterer() {
            // Position the map.
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(1.304414, 103.834006), 17));

            // Initialize the manager with the context and the map.
            // (Activity extends context, so we can pass 'this' in the constructor.)
            mClusterManager = new ClusterManager<>(this, mMap);

            // Point the map's listeners at the listeners implemented by the cluster
            // manager.
            mMap.setOnCameraIdleListener(mClusterManager);
            mMap.setOnMarkerClickListener(mClusterManager);
            mMap.setOnInfoWindowClickListener(mClusterManager); //added
            mMap.setInfoWindowAdapter(mClusterManager.getMarkerManager());

            // Listener for Info-Window Click , Parse data to next activity.
            mClusterManager.setOnClusterItemInfoWindowClickListener(new ClusterManager.OnClusterItemInfoWindowClickListener<StoreLatLng>() {
                @Override
                public void onClusterItemInfoWindowClick(StoreLatLng myItem) {
                    Intent intent = new Intent(LocationRemitActivity.this, SelectedStoreDetail.class);
                    intent.putExtra(EXTRA_NAME, myItem.getTitle());
                    intent.putExtra("snippet", myItem.getSnippet());
                    Bundle args = new Bundle();
                    args.putParcelable("latlng", myItem.getPosition());
                    intent.putExtra("bundle", args);
                    startActivity(intent);
                }
            });

            // Setting Cluster On Click ~> Zoom in 1 level .
            mClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<StoreLatLng>() {
                @Override
                public boolean onClusterClick(final Cluster<StoreLatLng> cluster) {
    //                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(cluster.getPosition(), (float) Math.floor(mMap.getCameraPosition().zoom + 1)), 300, null);
                    BottomSheetDialogFragment bottomSheetDialog = BottomSheetDialogFragment.getInstance();
                    bottomSheetDialog.show(getSupportFragmentManager(), "Custom Bottom Sheet");
                    return true;
                }
            });

            // Add cluster items (markers) to the cluster manager.
            addItems();
        }


        //

        private void addItems() {

            // Firebase Setup to Retrieve Data
            FirebaseDatabase database = FirebaseDatabase.getInstance();
            DatabaseReference ref = database.getReference();
            ref.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                        if (postSnapshot.hasChild("Info")) {

                            // Get Data from Firebase (Name , Address , Lat , Lng)
                            String locationName = String.valueOf(postSnapshot.child("Info").child("Name").getValue());
                            String locationAddress = String.valueOf(postSnapshot.child("Info").child("Address").getValue());
                            double locationlat = (double) postSnapshot.child("Info").child("lat").getValue();
                            double locationlng = (double) postSnapshot.child("Info").child("lng").getValue();

                            if (locationName != null && locationAddress != null) {
                                // Create Marker inside MyItem + add markers to mClusterManager
                                StoreLatLng item = new StoreLatLng(locationlat, locationlng, locationName, locationAddress);
                                mClusterManager.addItem(item);
                            }
                        }
                    }
                }

                @Override
                public void onCancelled(DatabaseError error) {
                    // Failed to read value
                    Log.w(TAG, "Failed to read value.", error.toException());
                }
            });
公共类LocationReceiveActivity扩展了FragmentActivity在MapreadyCallback上的实现{
公共静态最终字符串EXTRA_NAME=“”;
私有静态最终字符串TAG=“TAG”;
私人群集管理器McClusterManager;
私有谷歌地图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u汇款位置);
把(这个)绑起来;
//获取SupportMapFragment,并在地图准备好使用时收到通知。
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(地图);
getMapAsync(这个);
}
@凌驾
4月1日公开作废(谷歌地图谷歌地图){
mMap=谷歌地图;
//标记簇
setupcluster();
mMap.getUiSettings().SetIndoorLevel PickerEnabled(false);
}
私有void setupcluster(){
//定位地图。
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(NewLatlng30103.834006),17);
//使用上下文和映射初始化管理器。
//(活动扩展了上下文,因此我们可以在构造函数中传递“this”。)
mClusterManager=newclustermanager(这个,mMap);
//将映射的侦听器指向集群实现的侦听器
//经理。
mMap.setonCameraideListener(mClusterManager);
mMap.setOnMarkerClickListener(mClusterManager);
mMap.setOnInfoWindowClickListener(mClusterManager);//已添加
setInfoWindowAdapter(mClusterManager.getMarkerManager());
//Listener for Info窗口单击,将数据解析到下一个活动。
mClusterManager.setOnClusterItemInfo窗口ClickListener(新建ClusterManager.OnClusterItemInfo窗口ClickListener()){
@凌驾
ClusterItemInfo窗口单击上的公共void(StoreLatlingMyItem){
意向意向=新意向(LocationTransmitActivity.this,SelectedStoreDetail.class);
intent.putExtra(额外的名称,myItem.getTitle());
intent.putExtra(“snippet”,myItem.getSnippet());
Bundle args=新Bundle();
args.putParcelable(“latlng”,myItem.getPosition());
意向。额外(“捆绑”,args);
星触觉(意向);
}
});
//点击设置集群~>放大1级。
mClusterManager.setOnClusterClickListener(新的ClusterManager.OnClusterClickListener(){
@凌驾
公共布尔onClusterClick(最终群集){
//mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(cluster.getPosition(),(float)Math.floor(mMap.getcamerposition().zoom+1)),300,null);
BottomSheetDialogFragment bottomSheetDialog=BottomSheetDialogFragment.getInstance();
show(getSupportFragmentManager(),“自定义底部工作表”);
返回true;
}
});
//将群集项目(标记)添加到群集管理器。
addItems();
}
//
私有void附加项(){
//Firebase设置以检索数据
FirebaseDatabase=FirebaseDatabase.getInstance();
DatabaseReference=database.getReference();
ref.addValueEventListener(新的ValueEventListener(){
@凌驾
公共void onDataChange(DataSnapshot DataSnapshot){
对于(DataSnapshot postSnapshot:DataSnapshot.getChildren()){
if(postSnapshot.hasChild(“信息”)){
//从Firebase获取数据(名称、地址、Lat、Lng)
String locationName=String.valueOf(postsnashot.child(“Info”).child(“Name”).getValue());
String locationAddress=String.valueOf(postsnashot.child(“Info”).child(“Address”).getValue());
double locationlat=(double)postSnapshot.child(“Info”).child(“lat”).getValue();
double locationlng=(double)postSnapshot.child(“Info”).child(“lng”).getValue();
if(locationName!=null&&locationAddress!=null){
//在MyItem内创建标记+将标记添加到mClusterManager
StoreLatLng项目=新的StoreLatLng(locationlat,locationlng,locationName,locationAddress);
McClusterManager.addItem(项目);
}
}
}
}
@凌驾
已取消的公共无效(DatabaseError错误){
//无法读取值
Log.w(标记“读取值失败”,error.toException());
}
});

你找到答案了吗?@RounakLahoti哈哈,不,我不知道怎么回事