I am developing an application which requires to mark the current location of an user onto google maps. I have already got the code for setting up a marker on the current location.
private void handleNewLocation(Location location) {
Log.d(TAG, location.toString());
//get the new latitude and longitude
double currentLatitude = location.getLatitude();
double currentLongitude = location.getLongitude();
//create object to store them
LatLng latLng = new LatLng(currentLatitude, currentLongitude);
//create marker with the new position
MarkerOptions options = new MarkerOptions()
.position(latLng)
.title("I am here!");
//add marker to the map
mMap.addMarker(options);
//move camera to current location
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
}
There are no errors shown on compilation. But when running on emulator , it displays "MapActivity has stopped working".
I am using Nexus 5 API 21x86 android virtual device to run the app.
Please help !!!!!!!
I think there is lots of problems, please refer to here, do it step by step, you will get the map.
Also, for the Marker part, please refer to here.
Related
I am currently building an awesome application that displays google map, then once there's a text message that contains long lat it will update the map. What I have tried is calling a function in broadcastreceiver ex.
String[] coords = smsBody.split(";");
String lat = coords[0];
String lng = coords[1];
Double newLat = Double.parseDouble(lat);
Double newLng = DOuble.parseDouble(lng);
mapActivityFragment mapFrag = new mapActivityFragment();
mapFrag.setLatLng(newLat, newLng);
The Google Map displays well on my onCreateView, but I am having a hard time; how can I get the lat lng from broadcastreceiver to display the new marker of the map
Upon checking some sources, I found some items that you can refer to:
updating google maps marker from a broadcast sms receiver
Updating an Activity from a BroadcastReceiver
Based on these sources, you need to create a private intent and BroadcastReceiver in your activity. Register this BroadcastReceiver once the activity starts. This will handle the setting up of marker to your map. Finally, invoke the private intent from the public BroadcastReceiver (SMS) by sending a broadcast containing the lat long values.
Hope this will help.
I wanna add Multiple Marker to esri map by using flex 4.6 on flash builder platform
`
private function addSomeMarkers(x:Number,y:Number):void
{
// This is just to show how to add markers
// using ActionScript code as opposed to MXML tags.
//(lat, lon, new SpatialReference(102697));
// outSR:SpatialReference = new SpatialReference(4326);
//GCS_WGS_1984
var myGraphicMarker:Graphic = new Graphic(new MapPoint(y,x, new SpatialReference(102100)),
new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 14, 0x009933));
myGraphicMarker.toolTip = "Marker added with ActionScript";
myGraphicsLayer.add(myGraphicMarker);
myGraphicMarker=null;
}`
These is my current function recives an (x,y) from dataBase but when i run program it just add only one the first recived x,y .
I checked my my code and im sure the function recives multiple point x,y....
Please help me and thank you>>>>>>>>>>>>>>>>>>>>>>>>>>>
I am working on same type of program and its working fine for me. May be you can try with some hard-coded values for Map points first. As I can see you are interchanging the positions of "y" and "X" in the map point.
var myGraphicMarker:Graphic = new Graphic(new MapPoint(y,x, new SpatialReference(102100)),
new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 14, 0x009933));
I am using Google Maps, and want to be able to detect if a user is in the radius of a Marker (placed on map), using the users current location. I have the users current location coordinates (latitude and longitude) and the marker's coordinates, but do not know how to calculate whether the user is in the area. The picture below might best describe what I want to do.
I have an algorithm like this:
map.OnInfoWindowClickListener(new OnInfoWindowClickListener()){
public void isUserInArea(Marker marker){
float[] distance = new float[2];
//users current location
Location.distanceBetween(currentLocation.getLatitude(),currentLocatiocation.getLongitude(),
marker.getPosition().latitude, marker.getPosition().longitude, distance);
}
Which doesn't find if the current location is within marker region because I can't get hold of the markers circle. It's the closest i've got to it however. Would appreciate help.
To help, I add a circle to a map like this
// adding circle to map
circleOptions = new CircleOptions();
circleOptions.center(new LatLng(locationlist.get(i)
.getLatitude(), locationlist.get(i).getLongitude()));
circleOptions.radius(20);
circleOptions.strokeColor(Color.BLUE);
circleOptions.fillColor(Color.BLUE);
map.addCircle(circleOptions);
//check that all tasks are in circle radius
Marker locationMarker = map.addMarker(markerOp);
locationMarker.showInfoWindow();
I use this:
Location.distanceBetween(mMarker.getPosition().latitude,
mMarker.getPosition().longitude, mCircle.getCenter().latitude,
mCircle.getCenter().longitude, distance);
if (distance[0] > mCircle.getRadius()) {
//Do what you need
}else if (distance[0] < mCircle.getRadius()) {
//Do what you need
}
Why don't you use proximity alerts?
This is what you can do: instead of drawing a circle, place a Marker on the map like so:
map.addMarker(new MarkerOptions()
.title(name)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.gpsmap))
.position(coordinates)
.flat(true)
.rotation(90));
and then add a proximity alert to it calling the following method:
// Proximity alert
private void addProximityAlert(double lat, double lng, int id){
Intent intent = new Intent(PROX_ALERT_INTENT);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, id, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
locationManager.addProximityAlert(lat, lng, POINT_RADIUS, EXPIRATION, proximityIntent);
}
where EXPIRATION = -1 (so the proximity alert doesn't expire) and POINT_RADIUS takes the values of the radius of your previous circle.
Then you need to add a proximity alert listener to the map:
IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
registerReceiver(new ProximityIntentReceiver(), filter);
where PROX_ALERT_INTENT = "yourProjectPackageName.ProximityActivity";
Hope this helps
This tutorial can help your requirement.
User entry exit proximity alert
all the best.
How can I control the Zoom Level of my Google Map with hyperlinks? For instance I want three defined levels (Location in UK, UK in Europe, Europe in the World). Clicking on these links will display the map with a different zoom level.
I'm using Google Maps API v3
That shouldn't be too difficult to do.
When you create the map, you get a reference to the map object, e.g.
var mapOptions = {mapTypeId: google.maps.MapTypeId.TERRAIN};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
Once you have the object, you can zoom to a specific level like this:
function zoomToLevel() {
map.setZoom(8);
}
So you'd just need to set the click event of your hyperlink to run the javascript function:
Zoom to level 8
For what you're doing though, it might be better to get the map to select it's own zoom level based on the area. This function is actually zooming to show the Pyrenees, but the idea could be used for any area, as long as your points are at diagonally opposite corners:
function zoomPyrenees() {
var startPoint;
var endPoint;
var boundsPyrenees;
startPoint = new google.maps.LatLng(43.373403, -1.774107);
endPoint = new google.maps.LatLng(42.482463, 3.129875);
boundsPyrenees = new google.maps.LatLngBounds();
boundsPyrenees.extend(startPoint);
boundsPyrenees.extend(endPoint);
map.fitBounds(boundsPyrenees);
}
I need to highlight a section of a street between two intersections. I have found a similar question which was asked more than a year ago (see here) which says that Google, Bing, etc. do not provide street data through their APIs. Does anyone know if anything has changed in the APIs, and whether I can get street location latitude/longitude data from somewhere now?
I have done this in API V2, but it should not be to difficult to rewrite it for V3.
Have a look at this website http://www.fvs.de/anfahrt.php (in German) and click the "Weg in Karte zeigen" buttons ("show way in map") in the sections below the map. Each button highlights another street line in the map.
It is basically done by using directions object of Google Maps to plot a route between two arbitrary street points in the map (e.g. your two intersections). The points must be encoded with their LatLng coordinates. Here is a code example (as said this is API V2):
function initMap() { // called by page onload event
if (GBrowserIsCompatible()) {
// Display the map, with some controls and set the initial location
gMap = new GMap2(document.getElementById("map_canvas"));
gMap.addControl(new GLargeMapControl());
// ...
gMap.setCenter(GLatLng(49.238326, 6.977761), 15);
// init directions object and attach listener to handle route loads from function highliteRoute()
gDir = new GDirections();
gPoly = null;
GEvent.addListener(gDir, 'load', function(){
gPoly = gDir.getPolyline();
gMap.addOverlay(gPoly);
// zoom & pan to poly
var polyBds = gPoly.getBounds();
var polyZoom = gMap.getBoundsZoomLevel(polyBds);
gMap.setZoom(polyZoom);
gMap.panTo(polyBds.getCenter());
});
}
}
function highliteRoute(){
if(gPoly!=null) gPoly.hide();
gDir.load('from: 49.313530,6.969109 to: 49.238326,6.977761', {getPolyline:true});
}