jQuery UI Map Control Click - android

I'm trying to create a button on the jQuery Ui Map, when the user clicks the button the map should panTo (or center) on the users location
I have the following control
<div id="userLocate" style="margin:15px 15px 15px 20px;padding:5px 5px 5px 10px;"><img src="img/locate.png"></div>
And this JS
$('#map_canvas').gmap().bind('init', function() {
//Set click event on userLocationControl
$('#userLocate').click(function(event) {
var lat = newPoint.lat();
var lng = newPoint.lng();
var np = new google.maps.LatLng(lat, lng);
console.log("lat: " + lat + " lng: "+ lng);
$('#map_canvas').gmap('get', 'map').panTo(np);
console.log("lat: " + np.lat() + " lng: "+ np.lng());
$('#map_canvas').gmap('option', 'zoom', 15);
});
//Add userLocationControl
$('#map_canvas').gmap('addControl', 'userLocate', google.maps.ControlPosition.RIGHT_BOTTOM);
});
When the button is clicked I can see the log writing the correct latitude and longitude before and after the call to panTo method, however the map is being panned to position 0,0. I've tried using the setCenter method and have the same result
If call the method outside the click function and send it the newPoint variable (which is a LatLng object) everything works fine

Finally made it, I had to add a return; statement, beats me... but it works

Related

get offline GPS coordinates on android device

Firstly, I'm not a developer or programmer so any help here would be really appreciated! I have a form for use on android mobile devices which launches in Google Chrome. The users can use this form when offline and I was wondering how best to get offline GPS co-ordinates in lat and long. I've been doing some digging around and the code below seems to work. I pull the lat, long and accuracy result from this code into a separate field on my form.
What I am not sure about is how to pull in a timestamp so that I can be assured the reading is current and not something cached on the device. The currency and reliability of the coordinates is very important to me.
Any help at all on this would be marvellous!!
Thanks, Angela
<!DOCTYPE html>
<html>
<body>
<p>Get your latitude and longitude (test this to ensure it works when out of coverage)</p>
<button onclick="getLocation()">Get your coordinates</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
"<br>Accuracy: " + position.coords.accuracy + '<br />'
}
function showPosition(position) {
var latlon = position.coords.latitude + "," + position.coords.longitude +", Accuracy " + position.coords.accuracy;
$('input[name="coords"]').val(latlon).trigger('input');
}
</script>
</body>
</html>
getCurrentPosition accepts a second parameter, PositionOptions. There are a few options you can experiment with to achieve desired results, but specifically you'll want to use maximumAge and enableHighAccuracy. To ensure uncached results:
navigator.geolocation.getCurrentPosition(function(pos){
console.log('Got position', pos);
}, {
// can be `0` = uncached, any number in milliseconds,
// or `Infinity` which will only retrieve cached results
maximumAge: 0,
// may take longer, but browser will do everything possible
// to get the most accurate position
enableHighAccuracy: true
});
It's also worth noting the returned Position comes with an accuracy property, which returns a positive double indicating the accuracy of your lat and long in meters. Depending on the use case, you may want to require a certain accuracy threshold for users to interact with your app. You can see the full spec here.

Mark in google maps a list of addresses - Android or PHP

I have a list of addresses and I want to mark this places all in google maps(nearly 1k), getting maybe its cordinates to save them.
Actually I am not programming an app, but I know both lenguages (Android and PHP) and I think it is possible to do this with both. Any idea ? Thank in advance!
Have you tried the google maps api?
https://developers.google.com/maps/documentation/geocoding/intro
https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding
This is what you are looking for I think.
EDIT: to mark stars on map
// In the following example, markers appear when the user clicks on the map.
// Each marker is labeled with a single alphabetical character.
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var labelIndex = 0;
function initialize() {
var bangalore = { lat: 12.97, lng: 77.59 };
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: bangalore
});
// This event listener calls addMarker() when the map is clicked.
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng, map);
});
// Add a marker at the center of the map.
addMarker(bangalore, map);
}
// Adds a marker to the map.
function addMarker(location, map) {
// Add the marker at the clicked location, and add the next-available label
// from the array of alphabetical characters.
var marker = new google.maps.Marker({
position: location,
label: labels[labelIndex++ % labels.length],
map: map
});
}

Trouble with the method: setOnMyLocationChangeListener

I've been trying some tutorials and basic exercises with Google Maps V2 and I'm stuck with something happening to my "setOnMyLocationChangeListener" method.
I'm running the following code:
this.mMap.setOnMyLocationChangeListener(new OnMyLocationChangeListener() {
#Override
public void onMyLocationChange(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lon = (int) (location.getLongitude() * 1E6);
Toast.makeText(
GoogleMapsV2_Interact.this,
"Coordss\n" + "Lat: " + lat + "\n" + "Lon: " + lon + "\n" ,
Toast.LENGTH_SHORT).show();
Log.d(TAG, "Event OnMyLocationChangeListener.");
}
});
If I understand correct this whole event is supposed to trigger only when the Location of the "My Location blue dot shown on the map" changes... but everytime I run the code on my devide I keep getting spamed with the toast of my code like the event is being triggered nonstop.
Is there something I'm missing , or something I'm not understanding ? I thought I was supposed to see my toasts only and only after a location change for the blue dot.
The documentation states that
Called when the Location of the My Location dot has changed (be it latitude/longitude, bearing or accuracy).
Maybe your bearing or accuracy is changing all the time - print them with the coordinates into the LogCat and see what's different from the previous log statements.

Clickable InfoBubble in Google Maps API 3

Good day!
I just want to ask if an InfoBubble can have a listener. I tried to insert the text of the InfoBubble in a div and insert an onclick command there, but nothing happens.
Thanks in advance. By the way I am currently developing an android application, and using webview to display the map.
ok, jetpro,
here's what I do in a similar scenario using javascript:
/* json data object requires:
data.Id,
data.Lat,
data.Lng,
data.Name,
data.Address,
data.Date
*/
function DisplayMapEvent(data, targetDiv) {
var latlng, options, map, contentString, infowindow, marker;
// setup our variables
latlng = new window.google.maps.LatLng(data.Lat, data.Lng);
options =
{
zoom: 15,
center: latlng,
mapTypeId: window.google.maps.MapTypeId.ROADMAP
};
// create the map inside our map <div> and apply the options
map = new window.google.maps.Map(document.getElementById(targetDiv), options);
map.setOptions(options);
// info to display in the infowindow popup
contentString =
'<div>' +
'<b style="color: #DC6852;">' + data.Name + '</b><br />' +
'Where: ' + data.Address + '<br />' +
'When: ' + data.Date + '<br />' +
'</div>';
// info/marker and popup objects setup
infowindow = new window.google.maps.InfoWindow({
content: contentString
});
marker = new window.google.maps.Marker({
position: latlng,
map: map
});
// add the usual suspect event handlers
window.google.maps.event.trigger(map, 'resize');
// to allow us to repoen a map marker infowindow if closed
window.google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
// open infowindow on map once rendered
infowindow.open(map, marker);
// sit back and wonder at the glory of google maps mow :-)
}
In my case, I'm passing a json object into the DisplayMapEvent function, but you could rejig this to your own requirement. This function is called anytime I wish to add a new marker onto my map, so you may be able to lift this wholesale and refactor as required.
Hope this helps.
Add listener like this
google.maps.event.addDomListener(infoBubble2.bubble_, 'click', function(){..});
Have fun!

Map View errors when I used it for the second time in Android (Titanium)

I have records on the table list contains data that has latitude & longitude on the listing widow. When I click on each row, it passes to the detail window that display the mapview and its annotation of that record.
I zoom in & out, moved to different area and I clicked "back" button to go back to the record list.
Then, I selected on the different record to see the map on the detail window again, when I'm on the detail window suddenly I clicked on the map, there, it alerts me an error message which did not mention about the specific issues.
Here is my code:
self.listingAnnotation = Titanium.Map.createAnnotation({
pincolor: Titanium.Map.ANNOTATION_RED,
latitude: latitude,
longitude: longitude,
animate: true
});
self.region = {
latitude: latitude,
longitude: longitude
};
if(!self._mapview){
self._mapview = Titanium.Map.createView({
top: 130,
bottom: 0,
animate:true,
mapType: Titanium.Map.STANDARD_TYPE,
region: {latitude: latitude, longitude: longitude},
annotations: [self.listingAnnotation]
});
}
else{
self._mapview.removeAllAnnotations();
self._mapview.setLocation(self.region);
self._mapview.addAnnotation(self.listingAnnotation);
}
self._listingDetailWindow.add(self._mapview);

Categories

Resources