As the title (very long, sorry didn't know how to reword it) states,
I'm after some help taking a location from a search bar and a radius
from a radio button, and then putting a marker at that location and a
circle around it using the selected radius, I can the search working
fine, and the drawing a circle bit works. I'm having trouble when it
comes to passing the radius to the addAddressToMap function. Because
the marker is added to the map in that function, thats where the LAT/
LNG values are so I need them for the centre of the circle, but I
can't get the radius in there because it is used posted to the
showLocation function. Sorry if it's unclear, heres the snippets of
code that should help explain:
Here is the search bar and radius radio buttons that are used by the
user
<form id="worldmap" method="post" action="#" onsubmit="showLocation
('worldmap'); return false;">
<input type="text" name="q" maxlength="100" class="q" />
<input type="radio" checked="check" name="r" value="15.5" />
25KM Radius
<input type="radio" name ="r" value="60" /> 100KM Radius
<input type="submit" name="Submit" value="GO" />
</form>
here is the draw circle function, pretty straight forward, radius is
where obviously a variable would go that is the users selected radius
// Draws the 100 mile circumference.
function drawCircle(lng,lat) {
var Cradius = 15.5; // mile radius
var Ccolor = '#0000ff'; // color blue
var Cwidth = 3; // width pixels
var d2r = Math.PI/180; // degrees to radians
var r2d = 180/Math.PI; // radians to degrees
var Clat = (Cradius/3963)*r2d; // using 3963 as earths
radius
var Clng = Clat/Math.cos(lat*d2r);
var Cpoints = [];
for (var i=0; i < 33; i++) {
var theta = Math.PI * (i/16);
Cx = lng + (Clng * Math.cos(theta));
Cy = lat + (Clat * Math.sin(theta));
Cpoints.push(new GPoint(Cx,Cy));
};
map.addOverlay(new GPolyline(Cpoints,'#0000ff',5));
}
here is the geocoding etc
function showLocation(form) {
var address = document.forms[form].q.value;
for (var i=0; i < document.forms[form].r.length; i++)
{
if (document.forms[form].r[i].checked)
{
var rad_val = document.forms[form].r[i].value;
}
}
geocoder.getLocations(address, addAddressToMap);
}
// Called when the geocoder returns an answer. It adds a
// marker to the map with a circle to indicate the 100
// mile radius.
function addAddressToMap(response) {
//map.clearOverlays();
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
} else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
var searchLNG = place.Point.coordinates[0];
var searchLAT = place.Point.coordinates[1];
marker = new GMarker(point);
map.addOverlay(marker);
drawCircle(searchLNG,searchLAT);
map.setCenter(point, zoomLevel)
}
}
So basically, I want what the user picked as the radius, to be inside
the addAddressToMap function to be used in drawCircle
Sorry if any of it is unclear, I'm in Aus (getting a bit late) so I'll
clear up any queries after I sleep, but if anyone spots anything or
has encountered this before I'd greatly appreciate any help, or if
anyone knows another way around this that I'm not thinking of
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---