I am trying to store my location into the parse.com database, but i have having an issue doing so. First of all, I can't store anything into the database I believe it is returning null or something so. Not quite sure whats the behavior. Can someone guide me in the right direction?
double longitude = location.getLongitude();
double latitude = location.getLatitude();
// Get longitude of the current location
// Create a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
ParseObject parkingobject = new ParseObject("Cooking");
parkingobject.put("username","Alana");
ParseGeoPoint point = new ParseGeoPoint(latLng); //<----- This is where the error is.
parkingobject.put("Location", point);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
ParseGeoPoint geoPoint = new ParseGeoPoint(latitude , longitude );
ParseObject parkingobject = new ParseObject("Cooking");
parkingobject.put("username","Alana");
parkingobject.put("Location", geoPoint );
Try this code.
Related
I'm creating a GPS like application with omsdroid, I successfully displayed a map and centered it on the user location, but I can't find a way to display an "user icon" on the map.
I'm new on android (started like one week ago) so please explain all step and add sample of code if you can, thanks.
edit :
here is my code so far :
edit :
here is my code so far :
public void onLocationChanged(Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
altitude = location.getAltitude();
accuracy = location.getAccuracy();
GeoPoint p = new GeoPoint( (latitude ), (longitude ));
myMapController.animateTo(p);
myMapController.setCenter(p);
mylocation = new MyLocationNewOverlay(new GpsMyLocationProvider(getApplicationContext()), mapView);
mylocation.enableMyLocation();
//mylocation.enableFollowLocation();
mapView.getOverlays().add(mylocation);
}
For enable user location icon you should add the MyLocationOverlay on your map:
org.osmdroid.views.MapView openMapView = (org.osmdroid.views.MapView) v.findViewById(R.id.openmapview);
MyLocationOverlay myLocationoverlay = new MyLocationOverlay(getActivity(), openMapView);
myLocationoverlay.enableMyLocation();
mMapView.getOverlays().add(mMyLocationNewOverlay);
I am working on application where i get MyLocation by Latitude and Longitude .Now I want to get the Users who is in 5 Km within my range .I am using following code to get the Lat and Long of User.
if(gps.canGetLocation()){
getlatitude = gps.getLatitude();
getlongitude = gps.getLongitude();
latitude_mString = String.valueOf(getlatitude);
longitude_mString = String.valueOf(getlongitude);
Log.d("Value of lat and long", latitude_mString+""+longitude_mString);
Log.d("u r", "ur in register lati loni");
new Thread(null,latlongThread,"").start();
}
}else{
gps.showSettingsAlert();
}
marker = new MarkerOptions().position(new LatLng(getlatitude, getlongitude)).title("Me");
//marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.));
CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(getlatitude, getlongitude))
.zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
googleMap.addMarker(marker);
return rootView;
}
By This Code i can get mylocation .I am storing each user data in my API .So i have all data regarding lat and long of each user .So now i want to print user who have location or lat and long within 5 km of me.
Use the location's distanceTo method
http://developer.android.com/reference/android/location/Location.html#distanceTo(android.location.Location)
How to show latitude and longitude which I received from server on android map. I implemented google map V2 but don't know how to show gps coordinates on map. I came here after a lot of research and wasn't able to find a single reasonable solution for it. Can anyone please help me out?
So far my code of latitude and longitude values which I am reviving from server.
String lat, lon;
double l1,l2;
DB db = new DB(getApplicationContext());
HashMap<String,String> gps = new HashMap<String, String>();
gps = db.getGps();
lat = user.get("lati");
lon = user.get("longi");
Okay when I try to add marker on map according to latitude and longitude from server my app got force close and gives NullPointerException.
free.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String lat, lon;
double l1,l2;
DB db = new DB(getApplicationContext());
HashMap<String,String> gps = new HashMap<String, String>();
gps = db.getGps();
lat = user.get("lati");
lon = user.get("longi");
l1 = Double.parseDouble(lat);
l2 = Double.parseDouble(lon);
map.addMarker(new MarkerOptions().position(new LatLng(l1, l2))
.title("My Map Title"));
Your "map" variable may not be initialized. I add a marker like this:
SupportMapFragment smf = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMap = smf.getMap();
if ( mMap != null ) {
LatLng newLatLong = new LatLng(dblLat, dblLong);
mMap.addMarker(new MarkerOptions().position(newLatLong)
.title(name)
.snippet(fullStrAddr));
}
Add a marker like this
Marker mymarker= map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
.title("My Map Title"));
This will set a marker at the latitude and longitude which was sent from the server..
Try it..
So I'm storing markers from my map into a sqlite database. I am trying to query the markers by latitude and longitude. So for testing I am adding the marker to a specific location. When I check the markers position it gives me another location. What is causing this?
private void drawMarker(LatLng point, String title, String snippet){
// Creating an instance of MarkerOptions
MarkerOptions markerOptions = new MarkerOptions();
// Setting latitude and longitude for the marker
LatLng l = new LatLng(37.52100000000001, -77.44800000000001);
markerOptions.position(l);
markerOptions.title(title);
markerOptions.snippet(snippet);
// Adding marker on the Google Map
googleMap.addMarker(markerOptions);
}
This is the code to extract the marker position
googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
marker1 = marker;
LatLng mlatlong = marker1.getPosition();
markerLat = Double.toString(mlatlong.latitude);
markerLng = Double.toString(mlatlong.longitude);
latitude = mlatlong.latitude;
longitude = mlatlong.longitude;
Log.i("Marker", mlatlong.latitude +","+mlatlong.longitude);
markerDialog();
}
});
This gives me the position
06-20 21:53:52.447: I/Marker(15221): 37.52100000569583,-77.44800008833408
In Java, and most other languages you'll come accross, double is not stored as a precise value.
You can read more here.
Also, it shouldn't really matter the locations you posted are extremely close to each other.
I was working with a Google map v2 oriented android project. In my program i retrieves the name,vicinity,latitude&longitude from the places api while touching on the info boxes of the markers.But it every time retrieves the same value.But it shows the correct result in the info boxes.How to solve this bug .Someone please solve this.
Code
for(final Place place : nearPlaces.results){
// Creating a marker
MarkerOptions markerOptions = new MarkerOptions();
// Getting latitude of the place
double latitude = place.geometry.location.lat;
double longitude = place.geometry.location.lng;
// Getting name
String NAME = place.name;
// Getting vicinity
String VICINITY = place.vicinity;
//final String REFERENCE = place.reference;
final String slat = String.valueOf(latitude);
final String slon = String.valueOf(longitude);
LatLng latLng = new LatLng(latitude, longitude);
// Setting the position for the marker
markerOptions.position(latLng);
// Setting the title for the marker.
//This will be displayed on taping the marker
markerOptions.title(NAME + " : " + VICINITY);
markerOptions.icon(bitmapDescriptor);
// Placing a marker on the touched position
mGoogleMap.addMarker(markerOptions);
mGoogleMap.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
#Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
arg0.hideInfoWindow();
alert.showpickAlertDialog2(PlacesMapActivity.this, slat, slon, place.reference,KEY_TAG);
}
}
);
}
LatLng mylatLng = new LatLng(mylatitude, mylongitude);
// Creating CameraUpdate object for position
CameraUpdate updatePosition = CameraUpdateFactory.newLatLng(mylatLng);
// Creating CameraUpdate object for zoom
CameraUpdate updateZoom = CameraUpdateFactory.zoomBy(10);
// Updating the camera position to the user input latitude and longitude
mGoogleMap.moveCamera(updatePosition);
// Applying zoom to the marker position
mGoogleMap.animateCamera(updateZoom);
What you are doing wrong is setting OnInfoWindowClickListener in a loop.
Take that code outside and retrieve slat and slon from Marker arg0 by using getPosition.
There are other people who are struggling with this issue as well.
You are assuming that the slat and slong values are going to carry through to the onInfoWindowClick() method, but you are always getting the same values there.
Here is a discussion some other folks were having on this topic.