How to convert from location (address) String to YGeoPoint in the Google Maps API?

I have a list of addresses from the database for which I would like to place markers on a Yahoo map. The method addMarker()on YMap accepts YGeoPoint, which requires latitude and longitude. However, Yahoo Maps must know how to convert from addresses, because it drawZoomAndCenter(LocationType,ZoomLevel)can accept an address. I could convert using drawZoomAndCenter(), then getCenterLatLon(), but is there a better way that does not require anyone?

+3
source share
2 answers

You can ask the map object to perform geocoding and catch a callback:

<script type="text/javascript"> 
var map = new YMap(document.getElementById('map'));
map.drawZoomAndCenter("Algeria", 17);

map.geoCodeAddress("Cambridge, UK");

YEvent.Capture(map, EventsList.onEndGeoCode, function(geoCode) {
    if (geoCode.success)
        map.addOverlay(new YMarker(geoCode.GeoPoint));
});
</script>

- drawAndZoom geoCoding, . , GeoPoint.

+1

, geocoder.us, API.

, Google Maps Hacks , "Hack 62. " .

-1

Source: https://habr.com/ru/post/1696971/


All Articles