2014-06-20 63 views
0

只是一個初學者在這裏如此裸露與我! :)Google Maps Engine API指南?

我正在嘗試構建一個Android應用程序,用於在線存儲我的用戶位置,並與使用我的應用程序的所有人共享。我設法拼湊下面的代碼:

package com.example.test; 

import java.util.List; 
import com.google.android.gms.maps.*; 
import com.google.android.gms.maps.model.*; 
import android.app.Activity; 
import android.content.Context; 
import android.location.Location; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.widget.EditText; 

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); 
    List<String> providers = lm.getProviders(true); 
    Location l = null; 
    for (int i = providers.size() - 1; i >= 0; i--) 
    { 
     l = lm.getLastKnownLocation(providers.get(i)); 
     if (l != null) 
      break; 
    } 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 
    LatLng mapCenter = new LatLng(l.getLatitude(),l.getLongitude()); 
    float heading = l.getBearing(); 
    float speed = l.getSpeed();  
    EditText et= (EditText) findViewById(R.id.editText1) ; 
    et.setText(heading + " " + speed); 
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapCenter, 13)); 
    map.addMarker(new MarkerOptions() 
      .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)) 
      .position(mapCenter) 
      .flat(true) 
      .rotation(245)); 
    } 
} 

這這裏工作到,它得到我的當前位置,方位,速度,並繪製了我的Android手機上的地圖上。 現在我需要發送這個數據的地方,並從那裏得到其他用戶... 我一直在閱讀所有在網上如何做到這一點,但我沒有提出任何一步一步的例子.. .. :( 我已經閱讀幾乎所有的東西: 谷歌數據存儲區API 谷歌雲存儲API 谷歌地圖引擎API

這三個應該是能夠做到這一點以某種形式或其他,但我只是不有足夠的代碼片把它放在一起...

我寧願不必做HTTP,只是用Java作爲我的上述代碼的一部分...

任何幫助將不勝感激! 謝謝。

回答

0

沒有任何解決方案不涉及服務器和HTTP。即使你直接在兩部手機之間發送信息,你也需要一個服務器中介。可能你想要在線更新數據庫(使用AsyncTask發送HTTP POST),然後從服務器請求位置(使用偶爾輪詢它的服務或設置websocket - 對後者沒有好的指導)。另一個你希望服務器處於中間狀態的原因是要考慮身份驗證,因此沒有人可以通過反向工程來請求或截取他們不應該訪問的用戶的位置數據。

+0

ok http ...怎麼樣?我一直在閱讀谷歌數據存儲幫助頁面上下,似乎無法將它們粘在一起... – user2527849