วิธีใส่ geopoint จากตำแหน่งปัจจุบันของผู้ใช้ใน parse.com

ดังนั้นฉันจึงยังใหม่กับการเขียนโปรแกรมฐานข้อมูลเช่นเดียวกับการเขียนโปรแกรม Android ฉันกำลังพยายามรับตำแหน่งของผู้ใช้และจัดเก็บตำแหน่งไว้ในฐานข้อมูล parse.com ฉันเชื่อว่าโค้ดของฉันมาถูกทาง ใครสามารถช่วยฉันแก้ไขปัญหานี้ได้บ้าง

 import android.content.Context;
 import android.graphics.Color;
 import android.location.Criteria;
 import android.location.Location;
 import android.location.LocationManager;
 import android.os.Bundle;
 import android.support.v4.app.FragmentActivity;
 import android.util.Log;
 import android.widget.Toast;
 import com.google.android.gms.maps.CameraUpdate;
 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.model.BitmapDescriptorFactory;
 import com.google.android.gms.maps.model.LatLng;
 import com.google.android.gms.maps.model.MarkerOptions;
 import com.parse.ParseException;
 import com.parse.ParseGeoPoint;
 import com.parse.ParseObject;
 import com.parse.SaveCallback;
 import com.parse.SignUpCallback;

  public class MapsActivity extends FragmentActivity implements RoutingListener {
protected GoogleMap mMap;
protected LatLng start;
protected LatLng end;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    SupportMapFragment mMap = (SupportMapFragment)    getSupportFragmentManager().findFragmentById(R.id.map);

    try {
        setUpMapIfNeeded();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
@Override
protected void onResume() {
    super.onResume();

    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        // Try to obtain the map from the SupportMapFragment.
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            setUpMap();
        }
    }
}



private void setUpMap() {


    // Enable MyLocation Layer of Google Map
    mMap.setMyLocationEnabled(true);

    // Get LocationManager object from System Service LOCATION_SERVICE
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Create a criteria object to retrieve provider
    Criteria criteria = new Criteria();

    // Get the name of the best provider
    String provider = locationManager.getBestProvider(criteria, true);

    // Get Current Location
    Location myLocation = locationManager.getLastKnownLocation(provider);

    // set map type
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    // Get latitude of the current location

    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(true);
    mMap.getUiSettings().setCompassEnabled(true);
    mMap.getUiSettings().setRotateGesturesEnabled(true);
    mMap.getUiSettings().setZoomGesturesEnabled(true);


    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (location != null) {
        double longitude = location.getLongitude();
        double latitude = location.getLatitude();


        // Get longitude of the current location

        String userId = "O6pGXcJy3C";
        //String username = "Nick";
        ParseObject globeobject = new ParseObject("global");
         globeobject.put("username","Alana");

        globeobject.put("userID",userId);




         final ParseGeoPoint point = new ParseGeoPoint(latitude, longitude);
        globeobject.put("Location", point);

    }
}

@Override
public void onRoutingFailure() {
    // The Routing request failed
}

@Override
public void onRoutingStart() {
    // The Routing Request starts
}

}

person Community    schedule 28.06.2015    source แหล่งที่มา


คำตอบ (1)


ฉันเชื่อว่าคุณได้ทำสิ่งที่จำเป็นแล้ว ที่จุด "ParseGeoPoint สุดท้าย = ParseGeoPoint ใหม่ (ละติจูด, ลองจิจูด); Globeobject.put ("ตำแหน่ง", จุด);" ใส่บรรทัด

globeobject.saveInBackground();
person Hashan Seneviratne    schedule 01.07.2015