I'm doing this for an university assignment. i'm doing a web application based on the apis of ebay and google maps. in practice, i make an api call in ebay and i put the results in a table. Now, clicking on the location of each item i got as a result, i want to geocode the address in a google map. i wrote the php code for ebay apis and the javascript code for the google maps apis as follows:
php code for ebay apis...
foreach($resp->searchResult->item as $item){
$_i = 1;
// Determine which price to display
if ($item->sellingStatus->currentPrice) {
$price = $item->sellingStatus->currentPrice;
} else {
$price = $item->listingInfo->buyItNowPrice;
}
$itemLocation = $item->location;
// For each item, create a cell
$results .= "<tr> \n<td $thisCellColor valign=\"top\"> \n";
$results .= "<img src=\"$item->galleryURL\"></td> \n";
$results .= "<td $thisCellColor valign=\"top\"> <p><a href=\"" . $item->viewItemURL . "\">" . $item->title . "</a></p>\n";
$results .= 'Shipped to: <b>' . $item->shippingInfo->shipToLocations . "</b><br> \n";
$results .= 'Current price: <b>$' . $price . "</b><br> \n";
$results .= "Location: <INPUT TYPE=\"button\" id=\"$_i\" VALUE=\"$itemLocation\" onclick='clickToGeocode($_i);' <br>";
$results .= "</FORM> \n";
$results .= "</td> </tr> \n\n";
$_i = $_i + 1;
}
javascript code for google maps:
function clickToGeocode(id){
var address = document.getElementById(id).value;
document.write(id);
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
The problem is that every time I try to geocode a location the map goes to the location of the first item found in ebay..I mean the $_i (in php) and the id (in javascript) is always 1.. How can I resolve this??any idea?? thanks..