gpt4 book ai didi

android - 如何在 parse.com 中从用户当前位置放置一个地理点

转载 作者:行者123 更新时间:2023-11-29 01:31:16 24 4
gpt4 key购买 nike

所以我是数据库编程和 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
}

}

最佳答案

我相信您已经完成了必要的工作。在“final ParseGeoPoint point = new ParseGeoPoint(latitude, longitude); globeobject.put("Location", point);"lines put

globeobject.saveInBackground();

关于android - 如何在 parse.com 中从用户当前位置放置一个地理点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31104486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com