Google Maps V3, Directions stopped working [duplicate] - javascript

i have a separate code for google maps v3. Just for show infowindow infobox in my google fusion kml layer when i click on it. Yesterday my code is work fine. i didn't make any change. but today my addListner not working. when i copy my back up project, same as code. it work again but tomorrow that happens again. My addListener not work.
here's my code
infoBubble = new InfoBubble({
map: map,
shadowStyle: 1,
padding: 5,
borderRadius: 4,
arrowSize: 20,
borderWidth: 1,
borderColor: '#2c2c2c',
disableAutoPan: true,
hideCloseButton: false,
backgroundClassName: 'phoney',
arrowStyle: 2,
});
function get_details(mode,id,lati,lng)
{
$('#loading').show();
if (xhr != null)
{
xhr.abort();
}
xhr = $.ajax({
type: "GET",
url: "realisasi2.php?id="+id,
data: "m="+mode+"&id="+id,
success: function(ret){
ajaxres = JSON.parse(ret);
iconpos = new google.maps.LatLng(lati,lng);
psbchurndata = ajaxres.detail;
var html = psbchurndata+"<i><a class='ajax' href='#' onclick=layer22("+id+","+lati+","+lng+") style='font-family: Arial;font-size: 12px; color:#00CC29;'>Lihat Datel </a></i>";
infoBubble.setContent('<div class="infowindow"><br />'+html+'</div>');
infoBubble.setPosition(iconpos);
infoBubble.close();
infoBubble.open(map);
$('#loading').hide();
}
});
}
layer.setMap(map);
google.maps.event.addListener(layer, 'click', function(e) {
alert(JSON.stringify(e, null, 4)); //UNDIFINED not Working
var lati = e.latLng['mb'];
var lng = e.latLng['nb'];
var x = e.row['id_witel'].value;
get_details('w',e.row['id_witel'].value,lati,lng);
});
}
thank's for any help

There are no "official" properties mb and nb for a google.maps.LatLng(that's what e.latLng is) . These properties will be used internally by the API, the names of these properties may change the next moment, hour or day.
To retrieve latitude and longitude use the methods lat() and lng() of e.latLng

Related

How to use Pagination in Google Maps and Ajax

I have an api where is pagination because of a lot of data. Now I am trying to do Google Maps where I use API to get lat and lng from database. I still get just first page of API Data. What's wrong with my code ? What should I change. Please help. I will be glad to you.
Hi. I have an api where is pagination because of a lot of data. Now I am trying to do Google Maps where I use API to get lat and lng from database. I still get just first page of API Data. What's wrong with my code ? What should I change. Please help. I will be glad to you.
<script>
function initMap(map) {
var start_point = new google.maps.LatLng(27.772321, 1.803125);
// Creating a new map
var map = new google.maps.Map(document.getElementById("companies-map"), {
center: start_point,
zoom: 2,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
function setMarkerPoints(map) {
var bounds = new google.maps.LatLngBounds();
var mc = [];
var infoWindow = new google.maps.InfoWindow();
url = '/api/companies/map/',
$.ajax({
type: "GET",
url: url,
dataType: "json",
success: function(data, pagination) {
$.each(data.results, function(marker, data) {
var latLng = new google.maps.LatLng(data.point.latitude, data.point.longitude);
bounds.extend(latLng);
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
animation: google.maps.Animation.DROP,
map: map,
});
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent('' + data.name + '<br>' + data.name);
infoWindow.open(map, marker);
});
mc.push(marker);
});
if (pagination.hasNextPage) {
pagination.nextPage();
};
new MarkerClusterer(map, mc, {
imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
},
error: function(data) {
console.log('Please refresh the page and try again');
}
});
//END MARKER DATA
// end loop through json
}
setMarkerPoints(map);
}
google.maps.event.addDomListener(window, 'load', renderGoogleMap);
renderGoogleMap();
</script>
THANK YOU SO MUCH
You need to create a PlaceSearchPagination object in order to access additional pages. The object is created via a callback function.
https://developers.google.com/maps/documentation/javascript/places#place_search_responses
Take a look at the Accessing Additional Results section, specifically under the comments "// Create the places service" and "// Perform a nearby search.".

Combine listeners in Google Maps api v3 with google charts [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Integrate or mix Listeners from google map api with google chart table
I've created a map with google maps api v3 very simple, explained in code1.
As you can see, at the end of the code there is a Listener waiting for a click to be made on the marker/symbol to show the name of the marker.
Also I have a table (explained in code 2) made with Google Chart that have info related to the map.
What I need (and can't find) is when I click either the map or the table, the content related to it has to be highlighted/selected.
Clues/Tips:
Use new_map as global variable (didn't work)
how different is google.maps from google.visualization?
Has to be made with google.maps, because maps from google.visualization don't let rotate the markers.
**** I Will give special points :) ****
code1(Google Map Api):
function init_nuevo_mapa() {
var mapOptions = {
zoom: 13
center: new google.maps.LatLng(-33.5351136, -70.5876618)
};
var new_map = new google.maps.Map(document.getElementById('new-map'), mapOptions);
var myLatLng = new google.maps.LatLng(-33.5351136, -70.5876618)
var image = {
path: 'M 0,0 -10,-30 10,-30 z',
rotation: 10, //10º clockwise
fillColor: "red",
fillOpacity: 0.5,
scale: 1,
strokeColor: "red",
strokeWeight: 4
};
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
zIndex: zIndex,
title: location[2]
});
google.maps.event.addListener(marker, 'click', function () {
map.setZoom(13);
alert(marker.getTitle());
alert(marker.getPosition());
//marker.setVisible(false);
});
}
Code 2(Google Chart Table):
function drawChart() {
var datos_resumen = new google.visualization.DataTable();
datos_resumen.addColumn('string', 'Acción');
datos_resumen.addColumn('string', 'Celda');
datos_resumen.addColumn('number', 'Prioridad actual');
datos_resumen.addColumn('number', 'Prioridad nueva');
datos_resumen.addColumn('number', 'Distancia [km]');
datos_resumen.addRow([
"Cambiar",
resultado_vecino[i][2],
resultado_vecino[i][3],
resultado_vecino[i][4],
Number(resultado_vecino[i][6].toPrecision(3))]);
var tabla_resumen = new google.visualization.Table(document.getElementById('resumen_div'));
tabla_resumen.draw(datos_resumen, {
showRowNumber: true
});
google.visualization.events.addListener(tabla_resumen, 'select', selectHandler);
function selectHandler(e) {
var selected = tabla_resumen.getSelection()[0];
if (selected) {
var celda = datos_resumen.getValue(selected.row, 1)
alert(celda);
var temp = $.ajax({
url: 'sql_coord_cell.php?celda=' + celda,
type: 'post',
dataType: 'json',
async: false
}).responseText;
var js_geo_data = JSON.parse(temp);
var location = new google.maps.LatLng(js_geo_data['lat'], js_geo_data['lon']);
var infowindow = new google.maps.InfoWindow
infowindow.setOptions({
content: celda,
position: location
});
infowindow.open()
}
}
}
Finally I did it.
I just had to define a empty global variable outside functions like this
var new_map;
because this wont work:
var new_map = new google.maps.Map(document.getElementById('new-map'), mapOptions);
With this I can access to the map object from others object to interact between them

Google Maps V3 JavaScript works only in Chrome?

I wrote a script that first geocodes an address and then displays a map of that address.
The trouble is, it only works in Chrome / Chromium. Other browsers (Firefox 10 & IE9) display a grey box. A problem that could be related, if I add a marker to the map, the marker does not show in Chrome.
I know that :
I connect with the API successfully with my API key.
The address is properly geocoded.
I use jQuery UI dialog to display the map. This, however, does not seem to be a problem. Removing the dialog and using a static div creates the same "grey box" result.
Below is my script, how I invoke it, and the website that I am using this on.
Here's the script:
function Map(properties)
{
var that = this;
// the HTML div
this.element = properties.element;
// address string to geocode
this.address = properties.address;
// title to use on the map and on the jQuery dialog
this.title = properties.title;
this.latlng = null;
this.map = null;
this.markers = [];
// geocode address and callback
new google.maps.Geocoder().geocode({'address': this.address}, function(data)
{
// geocoded latitude / longitude object
that.latlng = data[0].geometry.location;
// map options
var options =
{
zoom: 16,
center: that.latlng,
zoomControl: false,
streetViewControl: false,
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// create a map
that.map = new google.maps.Map(that.element, options);
// add a marker
that.markers.push(new google.maps.Marker({map: that.map,
position: that.latlng,
title: that.title + "\n" +
that.address}));
});
this.get_google_map = function()
{
return that.map;
}
// creates a jQuery UI dialog with a map
this.show_in_dialog = function()
{
// because the dialog can resize, we need to inform the map about this
$(that.element).dialog({ width: 400, height: 300, title: that.title,
resizeStop: function(event)
{
google.maps.event.trigger(that.map, 'resize');
},
open: function(event)
{
google.maps.event.trigger(that.map, 'resize');
}});
}
this.center = function()
{
that.map.setCenter(that.latlng);
}
}
Here's how I invoke it :
// grab the address via HTML5 attribute
var address = $("#address").attr("data-address");
// ... and the title
var title = $("#address").attr("data-title") + " Map";
var map_element = document.createElement('div');
// append the newly created element to the body
$("body").append(map_element);
// create my own map object
var map = new Map({ element : map_element,
address : address,
title : title });
// bind a link to show the map
$("#map_link").click(function()
{
map.center();
map.show_in_dialog();
return false;
});
And here's the URL of the problem (click on map):
http://testing.fordservicecoupons.com/dealer/30000/premium_coupon_page
Last but not least, I combine and obfuscate my JavaScripts, so what you see above is not exactly the same as in the source on the website.
This doesn't look good:
resizeStop: function(event) { google.maps.event.trigger(that.element, 'resize'); },
open: function(event) { google.maps.event.trigger(that.element, 'resize'); }
you trigger the resize-event on the element that contains the map(that.element), but you must trigger resize on the google.maps.Map-object (what should be that.map in this case)
Wow... Here was the issue.
The layout that I built was a fluid layout. So, one of the first CSS rules that I have written was:
img, div { max-width: 100%; }
So that divs and images can scale. Well, for whatever reason, Google maps DOES NOT like this rule with the end result being a grey box.
And so I added another rule - an exception for Google maps:
img.no_fluid, div.no_fluid { max-width: none; }
And then, in javascript:
// AFTER DIALOG CREATION
$(dialog).find('*').addClass("no_fluid");
The find('*') will get us all the descendants.
Viola!

Geolocation marker not appearing, Google Maps API V3

I'm building a mobile map using the Google Map API V3. The is a little different than a standard map in that I have categories of markers than you can turn on/off. Everything works great, but I can't seem to get geolocation working. I've tried every combination and code snippet I can find and at most I can get it to register the location request, but it will not display a marker there no matter what I do. I'm sure I'm doing something very simple wrong, but I'm very new to Javascript so the answer is evading me.
Here is a shortened version of my current code (contains an example of everything, but cuts out a lot of the repetitive variables). This example doesn't include the geolocation functions since I've tried so many in different ways I'm not sure which one I would even put on here. The toggleMarkers() function is what I'm using to turn on/off the markers and I'm guessing that's where the problem is for the geolocation marker being displayed. If you could show me how to implement geolocation within this code I would greatly appreciate it!
var markers = [];
function initialize() {
//Setting Map
var mapOptions = {
zoom: 18,
center: new google.maps.LatLng(45.73158,-122.636277),
mapTypeId: 'satellite'
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
map.setTilt(0);
//Marker Categories
var markerBuildings = {
category: 'buildings',
}
var markerParking = {
category: 'parking',
}
// Icons
var iconBuilding = new google.maps.MarkerImage('images/building.png',
new google.maps.Size(32, 37),
new google.maps.Point(0,0),
new google.maps.Point(16,32));
var iconAmphitheater = new google.maps.MarkerImage('images/amphitheater.png',
new google.maps.Size(32, 37),
new google.maps.Point(0,0),
new google.maps.Point(16,32));
//Coordinates
//Buildings
var vmcb = new google.maps.Marker({
position: new google.maps.LatLng(45.730513,-122.638106),
map: map,
url: 'http://www.google.com/',
icon: iconBuilding,
data: markerBuildings
});
markers.push(vmcb);
var vadm = new google.maps.Marker({
position: new google.maps.LatLng(45.730899,-122.637742),
map: map,
url: 'http://www.google.com/',
icon: iconBuilding,
data: markerBuildings
});
markers.push(vadm);
}
function toggleMarkers(attr,val) {
if (markers){
for (i in markers) {
if(markers[i].data[attr] == val){
var visibility = (markers[i].getVisible() == true) ? false : true;
markers[i].setVisible(visibility);
}
}
}
}
If you could show me how to implement geolocation within this code I would greatly appreciate it!
call getGeoLocation() (below) after you create the map object
function getGeoLocation() {
// http://stackoverflow.com/questions/3397585/navigator-geolocation-getcurrentposition-sometimes-works-sometimes-doesnt
var options = null;
if (navigator.geolocation) {
if (!browserChrome) {
// By using the 'maximumAge' option, the position
// object is guaranteed to be at most 15 seconds old.
// FF and Safari seem to like these options; Chrome does not
options={enableHighAccuracy: false, maximumAge: 15000, timeout: 30000};
}
else {
// Request a position. We only accept cached positions, no matter what
// their age is. If the user agent does not have a cached position at
// all, it will immediately invoke the error callback.
// http://dev.w3.org/geo/api/spec-source.html
// Chrome will not allow this submitted via the file:// protocol
options={maximumAge:Infinity, timeout:0};
}
navigator.geolocation.getCurrentPosition(function(position) {
centerIsSet = true
canGeolocate = true;
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(pos);
},
getGeoLocationErrorCallback(true),
options);
}
else {
// browser doesn't support geolocation
getGeoLocationErrorCallback(false);
}
}

how to create a custom pin on Bing maps v7

Can someone show me how to custom the pin for Bing maps, version 7.0 please? I'm experimenting with upgrading from version 6 which has a custom icon but I cant find anywhere that shows how to do this with version 7. I have the following code so far.
Many thanks,
var map = null;
var pinInfobox = null;
function GetMap()
{
map = new Microsoft.Maps.Map(document.getElementById("myMap"), {
credentials: "xxx",
height: 236,
width: 269,
enableClickableLogo: false,
enableSearchLogo: false,
mapTypeId: Microsoft.Maps.MapTypeId.road,
showDashboard: false});
var loc = new Microsoft.Maps.Location(47.592, -122.332);
var pin = new Microsoft.Maps.Pushpin(loc);
map.entities.push(pin);
map.setView({ center: loc, zoom: 6 });
}
check out the reference documentation which has an "icon" option to set a custom icon
http://msdn.microsoft.com/en-us/library/gg427629.aspx
There is a really good site that documents how to do this exact operation.
http://www.bingmapsportal.com/isdk/ajaxv7#Pushpins2
Here is the JavaScript from that site that says how to do it:
map.entities.clear();
var pushpinOptions = {icon: virtualPath + '/Content/SpaceNeedle.jpg', width: 30, height: 50};
var pushpin= new Microsoft.Maps.Pushpin(map.getCenter(), pushpinOptions);
map.entities.push(pushpin);

Categories