0

我想开发一个移动应用程序,它基本上会帮助您根据来自他们的地理位置信息来跟踪您的朋友和家人的位置。所以我明白,这将涉及获得他们的许可,在访问数据之前。钛应用程序开发:从智能手机接收地理位置

我对在Titnaium Appcelerator中开发应用程序有基本的了解。但是我需要帮助确定如何与第三方设备通信,请求许可并检索其地理位置。

我发展将非常类似于这样的应用程序:http://goo.gl/dvCgP

+0

我认为不需要任何权限。我们使用钛时允许位置信息。如果出现错误,您可以手动将权限添加到tiapp.xml,如ACCESS_NETWORK_STATE,ACCESS_MOCK_LOCATION,ACCESS_FINE_LOCATION –

回答

1

你可以做到这一点的唯一方法是通过建立一个中央网络服务,手机本身不能互相搜集GPS位置,而不管那么,您无法将所有其他手机信息存储在您自己的设备上。

设置一个网络服务,当手机发布它们时将保存GPS位置,然后让该服务返回他们连接的其他手机。一旦你建立了这个服务,在Titanium中使用它很简单:

// First lets get our position 
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST; 
Titanium.Geolocation.distanceFilter = 10; 
Titanium.Geolocation.getCurrentPosition(function(e) { 

    if (e.error) { 
     alert('Cannot get your current location'); 
     return; 
    } 

    var longitude = e.coords.longitude; 
    var latitude = e.coords.latitude; 

    // We need to send an object to the web service verifying who we are and holding our GPS location, construct that here 
    var senObj = {userid : 'my_user_id', latitude : latitude, longitude : longitude}; 
    // Now construct the client, and send the object to update where we are on the web server 
    var client = Ti.Network.createHTTPClient({ 
     onload : function(e) { 
      // Parse the response text from the webservice 
      // This response should have the information of the other users youre connected too 
      var rsp = JSON.parse(this.responseText); 

      // do something with the response from the server 
      var user = rsp.otherUsers[0]; 
      alert('Tracking other user named '+user.userid+' at coordinates ('+user.longitude+','+user.latitude+')'); 
     }, 
     onerror : function(e) { 
      Ti.API.info('[ERROR] communicating with webservice.'); 
     } 
    }); 

}); 
相关问题