I am doing android app for field drawing and now I am making share function. Is there are any way to pass field coordinates from mobile to maps.google.com, make link, and send this link for example to friend via sms or email, that he just need to push the link and my drawed field will show up to him in browser? Is there any tool to do this or I need to create some web app for this?
Try out it
// To draw boundray on map
private void drawPolygon() {
polygonOptions = new PolygonOptions(); // consider new options
setStrokeWidth();
for (LatLng latLng : drawCoordinates) {
Marker marker = googleMap.addMarker(new MarkerOptions().position(latLng).title(latLng.toString()));
marker.setVisible(false);
polygonOptions.add(marker.getPosition()).strokeColor(Color.RED);
polygonOptions.fillColor(Color.TRANSPARENT);
polygonOptions.visible(true);
}
List<LatLng> points = polygonOptions.getPoints();
if (!points.isEmpty()) {
polygon = googleMap.addPolygon(polygonOptions);
Log.i("Poly lines","Successfully added polyline on map");
}
}
Related
I'm in a project with Xamarin Forms and OpenStreetMap.
I'm trying get the coordinates in the center of map.
This my code that create the map
public static Map CreateMap(double latitud, double longitud)
{
map = new Map();
var location = new Point(longitud, latitud);
var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(location.X, location.Y);
map.Layers.Add(OpenStreetMap.CreateTileLayer());
map.Home = n => n.NavigateTo(sphericalMercatorCoordinate, map.Resolutions[15]);
return map;
}
This is my code in file xaml.
<maps:MapView x:Name="MapView"
TouchMove="MapView_TouchMove"
MyLocationFollow="True"
IsMyLocationButtonVisible="False"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand" />
Try adding a method "TouchMove". But only get Bounds of map and not the coordinate.
private void MapView_TouchMove(object sender, Mapsui.UI.TouchedEventArgs e)
{
var center = MapView.Bounds.Center;
}
So, try add a Method MapClicked, for invoke this method from "MapView_TouchMove" but i dont know how invoke.
private void MapView_MapClicked(object sender, MapClickedEventArgs e)
{
var lat = e.Point.Latitude;
}
Any idea..???
Thanks.
looking at the API docs, Envelope appears to return what you want
Gets the extents of the map based on the extents of all the layers in
the layers collection
The MapView control has a Map property, from which you can get Envelope
I'm using this library to show a kml markers in a map in Android Maps V2.
I´m trying to get the lat and lon from a kml layer to do zoom directly to a placemark after add it to a map.
I tried to do this:
layer = new KmlLayer(mMap,R.raw.ruta, this );
layer.addLayerToMap();
for (KmlPlacemark act : layer.getPlacemarks()){
System.out.println("hi");//not iterate
}
but it doesn´t enter in the loop I read this kml-feature but don't work as is
You will have to read the 1st container of the KML-layer before attempting to read information about the placemarks:
KmlContainer = layer.getContainers().iterator().next();
if (kmlContainer == null) return;
for (KmlPlacemarks placemark : kmlContainer.getPlacemarks()) {
// Do the placemark magic here!
}
I'm trying out the Google API V2 Heatmap (Android) which was introduced this february and it's not working entirely. I'm not sure if it's the same problem as Google Maps API v2 HeatMap Won't Reliably Display (and I can't contact him by comments because I don't have enough rep.. :c ).
Using locations from file
Anyway, what I was trying to do was an App with just a GoogleMap and the same locations as in their guide (https://developers.google.com/maps/documentation/android/utility/heatmap) and when I launch it, I can only see 3/5 locations.
I tried adding more points and still, it's consistently not showing them all, but I can't see a pattern or something. The code is the same as in their guide.
private void addHeatMap() {
List<LatLng> list = null;
// Get the data: latitude/longitude positions of police stations.
try {
list = readItems(R.raw.police_stations);
} catch (JSONException e) {
Toast.makeText(this, "Problem reading list of locations.", Toast.LENGTH_LONG).show();
}
// Create a heat map tile provider, passing it the latlngs of the police stations.
mProvider = new HeatmapTileProvider.Builder()
.data(list)
.build();
// Add a tile overlay to the map, using the heat map tile provider.
mOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
}
private ArrayList<LatLng> readItems(int resource) throws JSONException {
ArrayList<LatLng> list = new ArrayList<LatLng>();
InputStream inputStream = getResources().openRawResource(resource);
String json = new Scanner(inputStream).useDelimiter("\\A").next();
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
double lat = object.getDouble("lat");
double lng = object.getDouble("lng");
LatLng latLng = new LatLng(lat, lng);
list.add(latLng);
}
return list;
}
Trying with weighted locations had the same result, some of them showing and some not.
Using locations "onClick"
In this case, normal LatLng were added and the map was updated until I got to the equator and then it stopped :p.
For the case of weightedLatLngs, it didn't update/show any :(
That's basically it... I don't know where to look for more information, whether it's something with the API, the device or something else.
Does anyone know why this might happen and/or where to look for a solution ?
Thank you in advance !
Btw, I'm using Android 4.0.4 on a Samsung Galaxy S Duos if that may prove useful..
The Googlemaps API for Heatmap only allows for 1,000 plotted points. You can reduced that by filtering out your original data or by converting to "weighted locations".
This looks like it was caused by this bug, where bounds calculations were excluding max values.
This is now fixed.
I am trying to use groundoverlay on Google Maps just to see if I can get an image on Google Maps. I have no error and looking through the documentation and examples. The image does not display.
Here is part of my code where I am implementing groundoverlay:
private GroundOverlay mGroundOverlay;
private static final LatLng NEWARK = new LatLng(40.714086, -74.228697);
.....
Under
protected void onCreate(Bundle savedInstanceState) {
.....
public void setImage(){
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 11));
mGroundOverlay = googleMap.addGroundOverlay(new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromResource(R.drawable.battery)).anchor(0, 1)
.position(NEWARK , 85000f,6500f));
}
I have the image "battery.jpeg" in my resource folder, drawable-hpdi
Can some look at my code and tell me what I am missing? Since I am a beginner in Android I would like an explanation as well.
Maybe I'm reading your intention incorrectly, but if you are trying to use the Android Maps API, you'll have to get a key from the API dashboard; the irreplaceable vogella has a tutorial:
http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html
if you are a new droidgrammer, I can think of no better programmer to learn from.
also, could you post your logcat? FYI: you can use Logcat Extreme on a rooted device to get live logging overlaid on your device that you can also send to file... it's the bee's knees and pouring over logcat readouts will accelerate your education greatly. =]
gl hf
Check this one
LatLng c1 = new LatLng( -33.67032801,151.30209310);
LatLng c2 = new LatLng( -33.66687426,151.30269820);
LatLng c3 = new LatLng( -33.66657936,151.30026840);
LatLng c4 = new LatLng( -33.67003309,151.29966320);
LatLngBounds latLngBounds = new LatLngBounds(c1, c3).including(c2).including(c4);
GroundOverlayOptions groundOverlayOptions = new
GroundOverlayOptions();
BitmapDescriptor bitmapDescriptor =
BitmapDescriptorFactory.fromAsset("h1.png");
groundOverlayOptions.image(bitmapDescriptor);
groundOverlayOptions.positionFromBounds(latLngBounds);
map.addGroundOverlay(groundOverlayOptions);
I have an Android application and I'm trying to populate a Google Map with a route, this route is store on a JSON array this way:
JSONArray.getString("points") = ["-33.45591917507404, -70.59198361376951","-33.453484420618416, -70.61635952929686"]
So in this case I have
Point A=(-33.49088437162095, -70.64043194102163) and
Point B=(-33.49423964397045, -70.63992768572683)
And my route or path is A-----B
I'm new to Android and I was wondering how to get this to work. Also, in this case my route is A-----B, but it can also be A----B----C----D. I can have any number of points on the path.
One thing you can try is the Google Maps Polyline object: https://developers.google.com/maps/documentation/javascript/reference#Polyline You specify to setPath() an ordered list of the points (either an Array of LatLng or an MVCArray or LatLng), you want to connect together on the map, and Google Maps will make a polyline for you to your specifications.
// path = Array of LatLng or MVCArray of LatLng
routeLine = new Polyline();
routeLine.setPath(JSONArray);
In your case, passing JSONArray into setPath should work OK.
If you want to get fancy and incorporate directions, you need to use the Google Directions API. https://developers.google.com/maps/documentation/javascript/directions
// All waypoints must be stopovers for the Directions service to optimize their route.
// start & end are of type String or LatLng, waypts is an array of String or LatLng
request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: [type Boolean],
travelMode: [type TravelMode]
};
// go on and actually perform the request
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
// if successful, this will run
}
});
Once you finish constructing your object, you should be able to display it by running setMap(map:Map), such as
routeLine.setMap(map)