-
18 Aug 2012 6:40 PM #1
Unanswered: How do I set the center coordinates of a map?
Unanswered: How do I set the center coordinates of a map?
{
xtype: 'map',
flex: 1,
mapOptions: {
zoomControl: false,
panControl: false,
rotateControl: false,
streetViewControl: false,
mapTypeControl: false,
zoom: 13
}
}
Hi all,
I got a map to show up in the container that I want, but I don't know how to show the map that I want. I don't mind just hard coding the coordinating... but later on, ideally use coordinates from a model.
Let's assume, Lat and Long are X and Y. How would I tell the map or mapOptions what location I want it to show me?
I have tried a few things, including:
1. Adding center to mapOptions..
center : new google.maps.LatLng(X, Y)
2. Adding 'LatLng' or 'latitute' and 'longitude' attibutes to map and mapOptions... but im just "hoping it works" rather than have a specific strategy with it.
Help!
Thanks!
Amrit
-
18 Aug 2012 10:49 PM #2
This will center the map on Apple Computer, Inc. headquarters and also drop a pin with a title that will show on hover.
app.js
Locations.jsCode:Ext.application({ name: 'test', views: ['Locations'], launch: function() { Ext.create('test.view.Locations'); } });
In HTML file's <head> section:Code:Ext.define('test.view.Locations', { extend: 'Ext.Panel', config: { layout: 'fit', fullscreen: true, items: [ { xtype: 'map', mapOptions: { center: new google.maps.LatLng(37.332495,-122.03056), zoom: 16, mapTypeId: google.maps.MapTypeId.ROADMAP, navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.DEFAULT } }, listeners: { maprender: function(extMapComonent, googleMapComponent) { var marker = new google.maps.Marker({ position: new google.maps.LatLng(37.332495,-122.03056), title: 'Apple Computer, Inc.', map: googleMapComponent, animation: google.maps.Animation.DROP, }); } } } ] } });
Code:<script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script>
-
20 Aug 2012 7:34 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
This works for me:
YOu have to be careful of using namespaces in properties like config objects as the Google API must be loaded before that class is defined.Code:new Ext.Map({ fullscreen : true, mapOptions : { zoomControl : false, panControl : false, rotateControl : false, streetViewControl : false, mapTypeControl : false, zoom : 13, center : new google.maps.LatLng(38.62452, -90.18514) } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote