myput
14 Sep 2011, 1:23 AM
Hello everybody,
i try to use google map API for give the user's current position and place it on marker map. But in all example, there is raw positions for latitude and longitude.
Is it not possible to initialize the center of the map on the user current position ??
I give you my code for trying to make better:
myApp.views.ShowCurrentPosMap = Ext.extend(Ext.Panel, {
layout:'card',
title: 'Map',
iconCls: 'maps',
initComponent: function(){
this.items = getMap();
myApp.views.ShowCurrentPosMap.superclass.initComponent.call(this);
}
});
Ext.reg('showCurrentPosMap', myApp.views.ShowCurrentPosMap);
In my Views, i call the function getMap who will create the map etc ...
After, in GeoLocation file, i have some functions:
var DefaultLat = 45.936661;
var DefaultLong = 6.630557;
function initInfoWindow(map) {
var infowindow = new google.maps.InfoWindow({
content: map.description,
});
return infowindow;
}
function setInfoWindow(infowindow, map, marker) {
infowindow.open(map, marker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
function setMarker(map, titlemap) {
var latlong = new google.maps.LatLng(DefaultLat, DefaultLong);
var marker = new google.maps.Marker({
position: latlong,
title : titlemap,
map: map
});
return marker;
}
function createNewMapPanel(map, titlepanel, xtypepanel) {
this.panel = new Ext.Panel({
layout: 'fit',
items: map,
dockedItems:[
{
xtype: xtypepanel,
title: titlepanel,
}
]
});
return this.panel;
}
function getMap() {
this.map = new Ext.Map ({
useCurrentLocation: true,
mapOptions : {
zoom: 12,
timeout: 10000,
maximumAge: 20000,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.DEFAULT
},
autoUpdate:true,
center: new google.maps.LatLng(DefaultLat, DefaultLong),
},
listeners: {
maprender : function(comp, map) {
var infowindow = initInfoWindow(map);
var marker = setMarker(map, map.title);
setInfoWindow(infowindow, map, marker);
}
}
});
return createNewMapPanel(this.map, 'My Map', 'toolbar');
}
Sorry for put all the code, i don't really know where is the problem.
I have in raw in the code:
var DefaultLat = 45.936661;
var DefaultLong = 6.630557;
var latlong = new google.maps.LatLng(DefaultLat, DefaultLong);
But i don't want. I want google map API find alone where is my current position and give variables in my code of that.
Is it possible ???
Thanks for your answers :)
i try to use google map API for give the user's current position and place it on marker map. But in all example, there is raw positions for latitude and longitude.
Is it not possible to initialize the center of the map on the user current position ??
I give you my code for trying to make better:
myApp.views.ShowCurrentPosMap = Ext.extend(Ext.Panel, {
layout:'card',
title: 'Map',
iconCls: 'maps',
initComponent: function(){
this.items = getMap();
myApp.views.ShowCurrentPosMap.superclass.initComponent.call(this);
}
});
Ext.reg('showCurrentPosMap', myApp.views.ShowCurrentPosMap);
In my Views, i call the function getMap who will create the map etc ...
After, in GeoLocation file, i have some functions:
var DefaultLat = 45.936661;
var DefaultLong = 6.630557;
function initInfoWindow(map) {
var infowindow = new google.maps.InfoWindow({
content: map.description,
});
return infowindow;
}
function setInfoWindow(infowindow, map, marker) {
infowindow.open(map, marker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
function setMarker(map, titlemap) {
var latlong = new google.maps.LatLng(DefaultLat, DefaultLong);
var marker = new google.maps.Marker({
position: latlong,
title : titlemap,
map: map
});
return marker;
}
function createNewMapPanel(map, titlepanel, xtypepanel) {
this.panel = new Ext.Panel({
layout: 'fit',
items: map,
dockedItems:[
{
xtype: xtypepanel,
title: titlepanel,
}
]
});
return this.panel;
}
function getMap() {
this.map = new Ext.Map ({
useCurrentLocation: true,
mapOptions : {
zoom: 12,
timeout: 10000,
maximumAge: 20000,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.DEFAULT
},
autoUpdate:true,
center: new google.maps.LatLng(DefaultLat, DefaultLong),
},
listeners: {
maprender : function(comp, map) {
var infowindow = initInfoWindow(map);
var marker = setMarker(map, map.title);
setInfoWindow(infowindow, map, marker);
}
}
});
return createNewMapPanel(this.map, 'My Map', 'toolbar');
}
Sorry for put all the code, i don't really know where is the problem.
I have in raw in the code:
var DefaultLat = 45.936661;
var DefaultLong = 6.630557;
var latlong = new google.maps.LatLng(DefaultLat, DefaultLong);
But i don't want. I want google map API find alone where is my current position and give variables in my code of that.
Is it possible ???
Thanks for your answers :)