I'm using MapQuest (since Google Map API will be down in september) and I'd like to add a point at an exact coordinates position.
I've created a movieClip named geoPoint and traced a circle in it.
Now, I've managed to display the coordinates in a text field like that :
if (Geolocation.isSupported){
var my_geo:Geolocation = new Geolocation();
my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
my_geo.setRequestedUpdateInterval(50);
var my_txt:TextField = new TextField();
my_txt.wordWrap=true;
addChild(my_txt);
}
function onGeoUpdate(e:GeolocationEvent):void{
my_txt.text = "My Latitude is "+e.latitude+" and my Longitude is "+e.longitude;
}
Now is it possible to add my movieClip at the e.latitude and e.longitude point ?
I've tried :
var geo:MovieClip;
geo = new geoPoint;
addChild(geo(new LatLng(e.latitude, e.longitude)));
but it doesn't work.
Someone knows how can I do it ?
Thanks !
It should be
geo = new geoPoint();
You should also probably figure how to translate latitude and longitude to x and y coordinates, because I'm doubtful the next line will work. You're calling a MovieClip constructor that takes a LatLng argument.
For what you need to achive, you may have to use a class provided by the MapQuest Api, like PolygonOverlay or CircleOverlay. There is an example here under "Shape Collections" http://developer.mapquest.com/content/as3/v7/7.0.6_MQ/samples/samplesexplorer/index.html#
Related
Hi I'm using google native geocoder class to search address.
Here is my code
final LatLng lowerLeft = SphericalUtil.computeOffset(latLng, DIST_200KM, 225);
final LatLng upperRight = SphericalUtil.computeOffset(latLng, DIST_200KM, 45);
List<Address> fromLocationName = geocoder.getFromLocationName(name, 25, lowerLeft.latitude, lowerLeft.longitude, upperRight.latitude, upperRight.longitude);
Ex:Expected search is "muruga theatre"
What i get is
Ex: 2) Typed Addr : M Address[addressLines=[0:"79, Kamaraj Salai, Ilango Nagar, Puducherry, 605013, India"], feature=79, admin=Puducherry, sub-admin=Pondicherry, locality=Puducherry, thoroughfare=Kamaraj Salai, postalCode=605013, countryCode=IN, countryName=India, hasLatitude=true, latitude=11.937229, hasLongitude=true, longitude=79.8231198, phone=null,url=null,extras=null]
Boundary lat lng: lower left ---> latlat/lng: (11.303572631938014,79.14103531980237) upper right --->lat/lng: (12.575374031508083,80.4410503605982)
Text doesnt match with the result. But the answer is correct. But when i try typing K. The address kamaraj salai wont show up.
Could anyone help me in knowing how actually geocoder class works in android.
I am trying to create an app that will launch a Google Maps Intent that will show the route to point A, passing through points B and C. I have the addresses and the LatLng of theses points.
Until now I tried to use just make a route from one pont to another using what is in this answer but it didn't work. When the Google Maps app opens it says that no route was found. The origin and destination fields are filled with the latitude and longitude of my points.
What am I doing wrong? Is there another way of doing this?
EDIT: Code I'm using to start the intent:
double ori_latitude = -90.0000000;
double ori_longitude = -60.0000000;
double dest_latitude = -90.0000000;
double dest_longitude = -54.0000000;
String uri = String.format(Locale.ENGLISH, "http://maps.google.com/dir ?saddr=%f,%f&daddr=%f,%f", ori_latitude, ori_longitude, dest_latitude, dest_longitude);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Just a quick glance says your code would work, but your coordinates point nowhere special, so I wouldn't be surprised if no route existed.
From a quick test, this works for me.
Seattle, WA to San Francisco, CA
double[] origin = { 47.605617, -122.332137 };
double[] dest = { 37.774821, -122.419462 };
Uri.Builder builder = new Uri.Builder()
.scheme("http")
.authority("maps.google.com/maps")
.appendQueryParameter("saddr", String.format(Locale.ENGLISH, "%f,%f", origin[0], origin[1]))
.appendQueryParameter("daddr", String.format(Locale.ENGLISH, "%f,%f", dest[0], dest[1]));
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(builder.build().toString()));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Code you have written is correct. There is issue with these coordinates.
Try changing coordinates, and see the magic. It works perfectly.
For eg:
double ori_latitude = 34.052222;
double ori_longitude = -118.243611;
double dest_latitude = 37.322778;
double dest_longitude = -122.031944;
Also, check the rules at
Google Maps
Tips for formatting your coordinates
Here are some tips for formatting your coordinates so they work on Google Maps:
Use the degree symbol instead of "d".
Use periods as decimals, not commas.
Incorrect: 41,40338, 2,17403. Correct: 41.40338, 2.17403.
List your latitude coordinates before longitude coordinates.
Check that the first number in your latitude coordinate is between -90 and 90.
Check that the first number in your longitude coordinate is between -180 and 180.
I am using Google Maps v2 in my application. When the user pans or zooms on the screen I would like to get the area of the map based on which I want to fetch the POI only in the screen view part.
I went through the documentation but could not find any help.
You need to use Projection and VisibleRegion classes in order to get visible LatLng region.
So your code would look something like:
LatLngBounds curScreen = googleMap.getProjection()
.getVisibleRegion().latLngBounds;
In Android(Kotlin) you can find LatLng this way, in every time zoom or. gesture detect
private var mMap: GoogleMap? = null
..........
mMap?.setOnCameraMoveStartedListener { reasonCode ->
if (reasonCode == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) {
val curScreen: LatLngBounds = mMap!!.getProjection().getVisibleRegion().latLngBounds
var northeast=curScreen.northeast
var southwest=curScreen.southwest
var center=curScreen.center
Log.v("northeast LatLng","-:"+northeast)
Log.v("southwest LatLng","-:"+southwest)
Log.v("center LatLng","-:"+center)
}
}
I have given coordinates for latitude and longitude, and I want make a location object with those.There isn't a constructor that takes to doubles to make a location, so I tried like this:
Location l = null;
l.setLatitude(lat);
l.setLongitude(lon);
but it crashes. Any different idea?
Just create a new Location with new Location("reverseGeocoded");
like this
GeoPoint newCurrent = new GeoPoint(59529200, 18071400);
Location current = new Location("reverseGeocoded");
current.setLatitude(newCurrent.getLatitudeE6() / 1e6);
current.setLongitude(newCurrent.getLongitudeE6() / 1e6);
current.setAccuracy(3333);
current.setBearing(333);
This crashes because you cannot call methods on an non existent object.
I presume you are talking about android.location.Location?
This is usually returned by the various positioning services of Android.
What do you want to do with it?
Do you want to reverse geocode it? As in find an address for that geo coordinate?
Or do you want to use it as a "fake" position and feed it to other applications?
There are BTW two constructors. One takes the name of a positioning service and the other is a copy constructor and takes an existing Location.
So you could create a Location like this:
Location l = new Location("network");
But I do not think that this will result in something you want to have.
Here is a link to the documentation:
https://developer.android.com/reference/android/location/Location.html#Location%28java.lang.String%29
Location l = new Location("any string");
l.setLatitude(lat);
l.setLongitude(lon);
Try this:
public double lat;
public double lon;
public void onLocationChanged(Location loc)
{
lat=loc.getLatitude();
lon=loc.getLongitude();
Toast.makeText(getBaseContext(),"Latitude:" + lat +Longitude"+lon,Toast.LENGTH_LONG).show();
}
This is maybe a noob question but im not 100% sure about it.
How can i make a Location Object using Geo points? I want to use it to get the distance between two points.
I already found a thread where it says
Location loc1 = new Location("Location");
loc.setLatitude(geoPoint.getLatitudeE6);
loc.setLongitude(geoPoint.getLongitudeE6);
Location loc2 = new Location("Location2");
loc2.setLatitude(geoPoint.getLatitudeE6);
loc2.setLongitude(geoPoint.getLongitudeE6);
and then i would use the distanceTo() to get the distance between the two points.
My Questions
What is the Providername for? ...new Location("What is this here???")
So do i have to define a Provider before or something?
I want to use this code in a for() to calaculate between more GeoPoints.
And btw - i have to convert the E6 Values back to normal?
Not exactly
loc.setLatitude() takes a double latitude. So the correct code is:
loc.setLatitude( geoPoint.getLatitudeE6() / 1E6);
Location() constructor take the name of the GPS provider used. It can be LocationManager.GPS_PROVIDER or NETWORK_PROVIDER among other values
To get the distance between two point you can use the Location class and more precisely the distanceBetween static method.
The doc is quite clear on what it does but here a quick code sample:
float[] results = new float[3];
Location.distanceBetween(destLatitude, destLongitude, mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude(), results);
// result in meters, convert it in km
String distance = String.valueOf(Math.round(results[0] / 1000)) + " km");
To convert from minute/second to degree you can use the convert method of the Location class.
Log.i("MapView", "Map distance to mark (in meters): " + myLocation.distanceTo(GeoToLocation(point)) + "m");
then
public Location GeoToLocation(GeoPoint gp) {
Location location = new Location("dummyProvider");
location.setLatitude(gp.getLatitudeE6()/1E6);
location.setLongitude(gp.getLongitudeE6()/1E6);
return location;
}