2016-06-09 55 views
1

我开发了一个带有用户登录名和注册信息链接到Firebase数据库的Android应用程序,我还添加了一个列表视图来存储添加到textView中的信息。使用GeoFire和Firebase添加用户位置到实时地图

我已经研究过使用GeoFire,因为我希望当前用户登录以显示在地图上。

我看看Firebase提供的一个示例,但我仍然不确定要做什么,但是没有多少关于此主题的教程。

这里是代码行可链接到公共数据库

private static final String GEO_FIRE_REF = "https://https://publicdata-transit.firebaseio.com/_geofire.firebaseio.com/_geofire"; 

我有显示这个样本账户的loaction地图。

我的问题是,有谁知道我可以如何将我的用户位置添加到地图?我对这项技术很陌生,对此我并不十分了解。

如果你需要更多的代码或inormation让我知道。

回答

1

设置位置

geoFire.setLocation("firebase-hq", new GeoLocation(37.7853889, -122.4056973)); 

要检查是否写入成功保存在服务器上,可以将GeoFire.CompletionListener添加到定义的setLocation电话:

geoFire.setLocation("firebase-hq", new GeoLocation(37.7853889, -122.4056973), new GeoFire.CompletionListener() { 
    @Override 
    public void onComplete(String key, FirebaseError error) { 
     if (error != null) { 
      System.err.println("There was an error saving the location to GeoFire: " + error); 
     } else { 
      System.out.println("Location saved on server successfully!"); 
     } 
    } 
}); 

请看看Official documentation为了完整的理解。

+0

我有位置设置为旧金山这是示例位置,我也不确定放置此代码的位置?你认为那段代码会在地图上添加我的用户位置吗?我正在做一个令人兴奋的服务。 –

相关问题