Google Maps : Show Map Via Address - google-maps

I have this Code To show map on a page
var _map = new GMap2($get("gmap"));
var _latLng = new GLatLng(lat, lng);
_map.setCenter(_latLng, 11);
_map.addControl(new GLargeMapControl());
_map.addControl(new GMapTypeControl());
var _icon = new GIcon(G_DEFAULT_ICON);
var marker = new GMarker(_latLng);
_map.addOverlay(marker);
But I do Not have GeoCode for Some Address.
How can I show Map via Address Only.

You use the GeoCoder to get the address into latitude and longitude first, and then use that.
Here's an example of how to geocode an address.

Related

how to move from one pin to another in google map click event in html

i have displayed multiple pins in google map with infoWindows,and there location name displayed in html page, now i need this when click on any location name moving pins from one to another, and have show it's infoWindow.
so, is there any solution?
http://i53.tinypic.com/hvec15.jpg
Here is my code
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(51.50015, -0.12624), 13);
// Creates a marker at the given point
// Clicking the marker will hide it
var marker = new GMarker(new GLatLng(lat, longt));
map.addOverlay(marker);
function createMarker(latlng, number) {
var marker = new GMarker(latlng);
marker.value = number;
GEvent.addListener(marker,"click", function() {
var myHtml = number + "";
map.openInfoWindowHtml(latlng, myHtml);
});
return marker;
}
// Add 5 markers to the map at random locations
// Note that we don't add the secret message to the marker's instance data
var bounds = map.getBounds();
for (index in markers){
var n=markers[index];
var latlng = new GLatLng(n.lat,n.lng);
map.addOverlay(createMarker(latlng, n.name));
}
marker.openInfoWindowHtml(WINDOW_HTML);
}
}
hey i got it with google map_lib,
see demo: login to see demo

google maps - javascript problem

I have a problem with google maps V3
Code is part of example from google. I want to add listener to EACH marker, so I set marker as array. But its not working :(
can anyone help me?
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
// Add 10 markers to the map at random locations
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
var marker = new Array(10);
for (var i = 0; i < 10; i++) {
var latlng = new GLatLng(southWest.lat() + latSpan * Math.random(),
southWest.lng() + lngSpan * Math.random());
marker[i] = new GMarker(latlng,{ draggable: true });
GEvent.addListener(marker[i] , "dragstart", function() {
map.closeInfoWindow();
});
GEvent.addListener(marker[i] , "dragend", function() {
marker[i].openInfoWindowHtml("text" + i);
});
map.addOverlay(marker[i] );
}
}
}
Google Maps v2 API is deprecated, you should use v3. See this working example using the new API: Google Maps JS API v3 - Simple Multiple Marker Example
This looks like Google maps api V2 code.
Replace GLatLng with google.maps.LatLng,
Replace GEvent with google.maps.event
Instead of map.addOverlay(marker[i]);, do marker[i].setMap(map); in V3.
For the rest, make sure to read the API documentation. There are lots of examples there that'll help you get going.

What's the coding for displaying many locations in google map using latitude and longitude value

I used this code but its not working.
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(10.35,79.4167), 13);
var marker = new GMarker(new GLatLng(10.35,79.4167));
map.setCenter(new GLatLng(8.7167,77.483), 14);
var marker = new GMarker(new GLatLng(8.7167,77.483));
map.setCenter(new GLatLng(21.83,78.75), 15);
var marker = new GMarker(new GLatLng(21.83,78.75));
map.addOverlay(marker);
map.setUIToDefault();
}
}
Your code will only add the last marker. You are only calling addOverlay once at the end (so only the last marker will be added to the map).
You also call setCenter multiple times, so only the last setCenter will be applied to the map. setCenter just sets the visible area on the Google Map.
You are using Google Maps v2 in your code, I suggest you check out the more current v3 API. If you are starting a new project, you may as well use the latest stuff.
If you have some other reason for using the v2 API, there is a range of good samples to get you started.

Best way to geocode UK postcode with Google Maps API?

What is the most effective and accurate way to geocode a UK postcode? Using the built in geocode object results in massively blurred results (lots of postcodes returning just a general area).
Are there any free UK postcode geocoding services I can plug into via JavaScript?
Edit: To be clearer this uses the local search in google search api, not the google maps api to do the geocoding which is much more accurate.
The best way is to use Google Search Api.
If you get an api key and get it all setup: http://code.google.com/apis/ajaxsearch/
var localSearch;
var map;
var icon;
var addressMarkerOptions;
google.load("search", "1");
google.load("maps", "2");
google.setOnLoadCallback(initialize);
function initialize()
{
localSearch = new GlocalSearch();
icon = new GIcon(G_DEFAULT_ICON);
addressMarkerOptions = { icon:icon , draggable: false};
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
plotAddress("OX4 1FJ");
}
/**
* This takes either a postcode or an address string
*
*/
function plotAddress(address)
{
localSearch.setSearchCompleteCallback(null,
function() {
if (localSearch.results[0])
{
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
var marker = new GMarker(point, addressMarkerOptions);
map.addOverlay(marker);
map.setCenter(point, 5, G_NORMAL_MAP);
}
else
{
alert('address not found');
}
});
localSearch.execute(address + ", UK");
}
I believe Live/Bing/Windows maps' API gives a much more accurate placement for a UK postcode than the Google maps API does.
Alternatively, there are databases of UK postcode data available, although they're quite costly. There are some interesting comments on this post: http://jamiethompson.co.uk/web/2008/07/24/full-uk-postcode-database-for-free/

How to add labels on Google Maps Pinpoints?

Creating a google map with store locations within 50 miles of user entered address. Have map & pinpoints showing correctly but all of the pinpoints just have a dot on them. I'd like to be able to label them A, B, C, D, etc so that I can list out locations & addresses in sidebar.
How would I do this? Here's the code I'm using to add my pinpoints.
var point = new GLatLng(latitude, longitude);
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function () {
map.openInfoWindowHtml(point, myHtml);
});
map.addOverlay(marker);
Excellent, thanks. Included this js library.
http://code.google.com/p/gmaps-utility-library/
And then all I needed to do was update the
var marker = new GMarker(point);
to this
var newIcon = MapIconMaker.createLabeledMarkerIcon({label: "A", primaryColor: "#FD766A"});
var marker = new GMarker(point, {icon: newIcon});