Googlemap Marker from GeoPoint - android

I have a Jar with geopoints, I use this bit of code to find the nearest city :
GetNService gn = new GetNService();
NGeoPoint nearest = gn.getN(lat, lon);
GeoPoint city = nearest.getPoint();
I would like to add a marker, but I don't know how to add with Geopoint.
Thanks

You can get the lat and lang values from a GeoPoint like so
GetNService gn = new GetNService();
NGeoPoint nearest = gn.getN(lat, lon);
GeoPoint city = nearest.getPoint();
double lat = city.getLatitude();
double lon = city.getLongitude();
you can add a Marker like so
map.addMarker(new MarkerOptions()
.position(new LatLng(lat, lon))
.title("Marker Title"));

Related

Update Marker position with Animation in Android Studio

I have successfully fetched the Latitude and Longitude from some data stored in the Database. But I am unable to update the marker location on the map. Can please someone help me with the code or as to how to do that.
Try this using CameraUpdate ,
LatLng coordinate = new LatLng(lat, lng); //Store these lat lng values somewhere. These should be constant.
CameraUpdate location = CameraUpdateFactory.newLatLngZoom(coordinate, 15);
mMap.animateCamera(location);
Or can also use this,
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(totalAddress); //Here Total Address is address which you want to show on marker
mMap.clear();
markerOptions.icon(
BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
markerOptions.getPosition();
mCurrLocationMarker = mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));

google maps marker array?

Hi guys and girls if any :))
this piece of code creates a null pointer exception
I would like to put a couple of markers in MO
LAT = Double.parseDouble(PartA);
LNG = Double.parseDouble(PartB);
LatLng Standort = new LatLng(LAT, LNG);
MO[y] = mMap.addMarker(new MarkerOptions()
.position(Standort)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.kreis)));
builder.include(MO[y].getPosition());
Array type expected - found com.google.android.gms.maps.model.maker
Definition private static Marker MOrt = null;
I don't know my answer help you out or not.
First of all declare array , than add points and for adding marker i just start a loop with add marker function.
LatLng[] point_new = new LatLng[3];
point_new[0] = new LatLng(24.8926596, 67.0835093);
point_new[1] = new LatLng(48.85837,2.294481);
point_new[2] = new LatLng(0, 0);
for (int i = 0; i < point_new.length; i++) {
drawMarker(point_new[i]);
}
//drawMarker method
private void drawMarker(LatLng point) {
// Creating an instance of MarkerOptions
MarkerOptions markerOptions = new MarkerOptions();
// Setting latitude and longitude for the marker
markerOptions.position(point);
// Adding marker on the Google Map
map.addMarker(markerOptions);
}
final output
hope this will help!
Happy coding

How to put marker on android map location?

After I find this Location mCurrentLocation = mLocationClient.getLastLocation(); how can I add a marker to that that location?
Making a marker like
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude))
requires a position object, is there a way that I can retrieve a position from the Location object? or is this done in some other way?
You can use the getLatitude() and getLongitude() of the Location class which will return double which by then you can pass it in your new LatLong constructor.
sample:
MarkerOptions marker = new MarkerOptions().position(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()))

Showing multiple markers in google map v2

i have a set of lat long coordinates. i want to display all of those markers at a time on google map. I know how to display a single marker. But don't know how to display multiples at once. Anybody please help me.
Thank you.
i have lat long points.
like
id = 123 lat = 12.00 lon = 77.00
id = 124 lat = 12.01 lon = 77.01
etc.
May This Help You
for(int pin=0; pin<pins.size(); pin++)
{
LatLng pinLocation = new LatLng(Float.parseFloat(pins.get(pin).latitude), Float.parseFloat(pins.get(pin).longitude));
Marker storeMarker = map.addMarker(new MarkerOptions()
.position(pinLocation)
.title(pins.get(pin).pinname)
.snippet(pins.get(pin).address)
);
}
Try this:
LatLng one = new LatLng(2.40744, 77.014702);//Latitude and long points
LatLng two = new LatLng(2.407440, 77.014702);
.......
Similarly u can use more lat and long
myMarkerOne = gm.addMarker(new MarkerOptions()
.position(one)//use LatLng obj
.title("C")
.snippet("dsfd")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
myMarkerTwo = gm.addMarker(new MarkerOptions()
.position(two)
.title("C")
.snippet("dsfds")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
refer this: How to add multiple marker and overlay in v2 google map?
Also check this link:
Create a LatLng object by using following format:
LatLng location = new LatLng(latitude, longitude);
Then call the method with your LatLng object along with your GoogleMap object:
private Marker setCurrentLocation(LatLng location, GoogleMap map) {
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory
.fromResource(R.drawable.user_location_pin);
Marker marker = map.addMarker(new MarkerOptions().position(location)
.icon(bitmapDescriptor).title(location.toString()));
return marker;
}

Android Update Current Location

So here is my method for getting the user saved location and then move camera to that location:
private void updatePlaces(){
locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location lastLoc = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
double lat = lastLoc.getLatitude();
double lng = lastLoc.getLongitude();
LatLng lastLatLng = new LatLng(lat, lng);
if(userMarker!=null) userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng)
.title("You are here")
.icon(BitmapDescriptorFactory.fromResource(userIcon))
.snippet("Your last recorded location"));
theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 3000, null);
}
How can i modify this code in order to get the new position only once, compare and then get camera to it?
Thank you in advance.
I don't understand you question, if you run the method updatePlaces() only ones it will getLastKnownLocation only once and updates the user marker only once. could you please be more explanatory on what you are trying to achieve?

Categories

Resources